Skip to content

Commit c1bc46c

Browse files
committed
refactor: HomeViewCoordinator stream task 관리 개선
1 parent d350929 commit c1bc46c

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Application/DevLogPresentation/Sources/Home/Home/HomeViewCoordinator.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ import DevLogDomain
1313
@MainActor
1414
@Observable
1515
final class HomeViewCoordinator {
16+
private enum AsyncStreamTaskID {
17+
case todoMutationEvent
18+
}
19+
1620
let viewModel: HomeViewModel
1721
let router = NavigationRouter<HomeRoute>()
1822
private let container: DIContainer
1923
@ObservationIgnored
2024
private var cancellable: AnyCancellable?
2125
@ObservationIgnored
22-
private var mutationTask: Task<Void, Never>?
26+
private var streamTasks = [AsyncStreamTaskID: Task<Void, Never>]()
2327

2428
init(container: DIContainer) {
2529
self.container = container
@@ -37,7 +41,7 @@ final class HomeViewCoordinator {
3741
}
3842

3943
deinit {
40-
mutationTask?.cancel()
44+
streamTasks.values.forEach { $0.cancel() }
4145
}
4246

4347
func fetchData() {
@@ -49,10 +53,10 @@ final class HomeViewCoordinator {
4953
}
5054

5155
func bindTodoMutationEvent() {
52-
guard mutationTask == nil else { return }
56+
guard streamTasks[.todoMutationEvent] == nil else { return }
5357

5458
let bus = container.resolve(TodoMutationEventBus.self)
55-
mutationTask = Task { [weak self] in
59+
streamTasks[.todoMutationEvent] = Task { [weak self] in
5660
let events = await bus.events()
5761
for await event in events {
5862
switch event {

0 commit comments

Comments
 (0)