From 5b85cd0a9d37b85008fe456209c5c46c22a79c43 Mon Sep 17 00:00:00 2001 From: Binh Le Date: Tue, 29 Oct 2024 19:25:50 +0700 Subject: [PATCH] AP-2214: Add back the deinit method so the task can be cancelled --- .../Sources/Accounts/Ads/ViewModel/AdsSlotViewModel.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Modules/Presentation/Features/Accounts/Sources/Accounts/Ads/ViewModel/AdsSlotViewModel.swift b/Modules/Presentation/Features/Accounts/Sources/Accounts/Ads/ViewModel/AdsSlotViewModel.swift index 9505d9d888..1d61020d70 100644 --- a/Modules/Presentation/Features/Accounts/Sources/Accounts/Ads/ViewModel/AdsSlotViewModel.swift +++ b/Modules/Presentation/Features/Accounts/Sources/Accounts/Ads/ViewModel/AdsSlotViewModel.swift @@ -29,6 +29,11 @@ final public class AdsSlotViewModel: ObservableObject { self.appEnvironmentUseCase = appEnvironmentUseCase } + deinit { + monitorAdsSlotChangesTask?.cancel() + monitorAdsSlotChangesTask = nil + } + // MARK: Setup func setupSubscriptions() { NotificationCenter.default @@ -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)