From ed65976025121c40c86a9ebb1ae31cf3c4168954 Mon Sep 17 00:00:00 2001 From: Chung Tran Date: Thu, 1 Feb 2024 15:10:37 +0700 Subject: [PATCH] fix: timer --- .../Common/PnL/AccountPnLRepository.swift | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/p2p_wallet/Common/PnL/AccountPnLRepository.swift b/p2p_wallet/Common/PnL/AccountPnLRepository.swift index 33aac8262..d8d75e845 100644 --- a/p2p_wallet/Common/PnL/AccountPnLRepository.swift +++ b/p2p_wallet/Common/PnL/AccountPnLRepository.swift @@ -38,27 +38,14 @@ class PnLProvider: Provider { } class PnLRepository: Repository { -// weak var timer: Timer? + weak var timer: Timer? override init(initialData: ItemType?, provider: PnLProvider) { super.init(initialData: initialData, provider: provider) -// timer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { [weak self] _ in -// guard let self else { return } -// Task { await self.refresh() } -// } - - // wtf timer doesn't fire??? - - scheduleRun() - } - - // MARK: - Scheduler - - private func scheduleRun() { - DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5 * 60)) { [weak self] in + timer = Timer.scheduledTimer(withTimeInterval: 5 * 60, repeats: true) { [weak self] _ in guard let self else { return } Task { await self.refresh() } - self.scheduleRun() } + timer?.fire() } }