move pollers to background threads

pull/541/head
Ryan Zhao 3 years ago
parent a86310b0f5
commit 16c9b7793a

@ -89,14 +89,16 @@ public final class ClosedGroupPoller : NSObject {
SNLog("Next poll interval for closed group with public key: \(groupPublicKey) is \(nextPollInterval) s.")
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)
Threading.closedGroupPollerQueue.async {
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)
}
}
}
}

@ -23,11 +23,11 @@ public final class OpenGroupPollerV2 : NSObject {
guard let strongSelf = self else { return }
strongSelf.hasStarted = true
strongSelf.timer = Timer.scheduledTimer(withTimeInterval: strongSelf.pollInterval, repeats: true) { _ in
DispatchQueue.global().async {
Threading.openGroupPollerQueue.async {
self?.poll().retainUntilComplete()
}
}
DispatchQueue.global().async {
Threading.openGroupPollerQueue.async {
strongSelf.poll().retainUntilComplete()
}
}

@ -55,7 +55,7 @@ public final class Poller : NSObject {
guard let strongSelf = self, strongSelf.isPolling else { return }
Timer.scheduledTimer(withTimeInterval: Poller.retryInterval, repeats: false) { _ in
guard let strongSelf = self else { return }
DispatchQueue.global().async {
Threading.pollerQueue.async {
strongSelf.setUpPolling()
}
}

@ -3,4 +3,8 @@ import Foundation
internal enum Threading {
internal static let jobQueue = DispatchQueue(label: "SessionMessagingKit.jobQueue", qos: .userInitiated)
internal static let pollerQueue = DispatchQueue(label: "SessionMessagingKit.pollerQueue")
internal static let closedGroupPollerQueue = DispatchQueue(label: "SessionMessagingKit.closedGroupPollerQueue")
internal static let openGroupPollerQueue = DispatchQueue(label: "SessionMessagingKit.openGroup")
}

Loading…
Cancel
Save