diff --git a/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift b/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift index 1142ff4d8..459b6c56b 100644 --- a/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift +++ b/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift @@ -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) + } } } } diff --git a/SessionMessagingKit/Sending & Receiving/Pollers/OpenGroupPollerV2.swift b/SessionMessagingKit/Sending & Receiving/Pollers/OpenGroupPollerV2.swift index b8d3b1eee..9e50c2717 100644 --- a/SessionMessagingKit/Sending & Receiving/Pollers/OpenGroupPollerV2.swift +++ b/SessionMessagingKit/Sending & Receiving/Pollers/OpenGroupPollerV2.swift @@ -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() } } diff --git a/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift b/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift index 9197e0a9e..e0bbe578f 100644 --- a/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift +++ b/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift @@ -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() } } diff --git a/SessionMessagingKit/Utilities/Threading.swift b/SessionMessagingKit/Utilities/Threading.swift index fb4a1dbba..83f34ffd6 100644 --- a/SessionMessagingKit/Utilities/Threading.swift +++ b/SessionMessagingKit/Utilities/Threading.swift @@ -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") }