Skip to content

Commit

Permalink
AP-2214: Add back the deinit method so the task can be cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
mega-bl authored and harryyan1238 committed Oct 29, 2024
1 parent 499156c commit 5b85cd0
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ final public class AdsSlotViewModel: ObservableObject {
self.appEnvironmentUseCase = appEnvironmentUseCase
}

deinit {
monitorAdsSlotChangesTask?.cancel()
monitorAdsSlotChangesTask = nil
}

// MARK: Setup
func setupSubscriptions() {
NotificationCenter.default
Expand Down Expand Up @@ -59,6 +64,7 @@ final public class AdsSlotViewModel: ObservableObject {

// MARK: Ads Slot changes
func monitorAdsSlotChanges() {
monitorAdsSlotChangesTask?.cancel()
monitorAdsSlotChangesTask = Task { [weak self, adsSlotChangeStream] in
for await newAdsSlotConfig in adsSlotChangeStream.adsSlotStream {
await self?.updateAdsSlot(newAdsSlotConfig)
Expand Down

0 comments on commit 5b85cd0

Please sign in to comment.