pull/408/head
nielsandriesse 3 years ago
parent 17688a66e6
commit 73eeff3ea1

@ -58,12 +58,16 @@ public final class ClosedGroupPoller : NSObject {
// MARK: Private API
private func setUpPolling(for groupPublicKey: String) {
poll(groupPublicKey).done2 { [weak self] _ in
DispatchQueue.main.async { // Timers don't do well on background queues
self?.pollRecursively(groupPublicKey)
}
}.catch2 { [weak self] error in
// The error is logged in poll(_:isBackgroundPoll:)
// The error is logged in poll(_:)
DispatchQueue.main.async { // Timers don't do well on background queues
self?.pollRecursively(groupPublicKey)
}
}
}
private func pollRecursively(_ groupPublicKey: String) {
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
@ -82,13 +86,17 @@ public final class ClosedGroupPoller : NSObject {
timers[groupPublicKey] = Timer.scheduledTimer(withTimeInterval: nextPollInterval, repeats: false) { [weak self] timer in
timer.invalidate()
self?.poll(groupPublicKey).done2 { _ in
DispatchQueue.main.async { // Timers don't do well on background queues
self?.pollRecursively(groupPublicKey)
}
}.catch2 { error in
// The error is logged in poll(_:)
DispatchQueue.main.async { // Timers don't do well on background queues
self?.pollRecursively(groupPublicKey)
}
}
}
}
private func poll(_ groupPublicKey: String) -> Promise<Void> {
guard isPolling(for: groupPublicKey) else { return Promise.value(()) }

Loading…
Cancel
Save