mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
27 lines
793 B
Swift
27 lines
793 B
Swift
import PromiseKit
|
|
|
|
@objc final class Poller : NSObject {
|
|
private var isStarted = false
|
|
private var currentJob: Promise<Void>?
|
|
|
|
// MARK: Configuration
|
|
private static let interval: TimeInterval = 30
|
|
|
|
// MARK: Initialization
|
|
@objc static let shared = Poller()
|
|
|
|
private override init() { }
|
|
|
|
// MARK: General
|
|
@objc func startIfNeeded() {
|
|
guard !isStarted else { return }
|
|
Timer.scheduledTimer(timeInterval: Poller.interval, target: self, selector: #selector(poll), userInfo: nil, repeats: true)
|
|
isStarted = true
|
|
}
|
|
|
|
@objc private func poll() {
|
|
guard currentJob == nil else { return }
|
|
currentJob = AppEnvironment.shared.messageFetcherJob.run().ensure { [weak self] in self?.currentJob = nil }
|
|
}
|
|
}
|