Skip to content

Commit

Permalink
fix: timer
Browse files Browse the repository at this point in the history
  • Loading branch information
bigearsenal committed Feb 1, 2024
1 parent f98f02e commit ed65976
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions p2p_wallet/Common/PnL/AccountPnLRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,14 @@ class PnLProvider: Provider {
}

class PnLRepository: Repository<PnLProvider> {
// 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()
}
}

0 comments on commit ed65976

Please sign in to comment.