mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Make ClientProxy.pauseServices async and drop its completion block
`pauseServices` took a completion block only because it was historically called from `deinit`, which can't await (the SE-0371 note). `deinit` now stops the sync itself, so the sole remaining caller is the AppCoordinator, which can await instead. Make `pauseServices` async and update the AppCoordinator background-task and lifecycle call sites to await it, calling the OS-facing completions (endBackgroundTask / setTaskCompleted) afterwards. This also removes the `MainActor.assumeIsolated` workaround — awaiting a @MainActor method hops onto the main actor cleanly — and fixes a latent bug where a nil `self` in the background app refresh expiration handler would skip setTaskCompleted.
This commit is contained in:
@@ -2470,20 +2470,20 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
|
||||
}
|
||||
//MARK: - pauseServices
|
||||
|
||||
private let pauseServicesCompletionCallsCountLock = NSLock()
|
||||
private var pauseServicesCompletionUnderlyingCallsCount = 0
|
||||
var pauseServicesCompletionCallsCount: Int {
|
||||
get { pauseServicesCompletionCallsCountLock.withLock { pauseServicesCompletionUnderlyingCallsCount } }
|
||||
set { pauseServicesCompletionCallsCountLock.withLock { pauseServicesCompletionUnderlyingCallsCount = newValue } }
|
||||
private let pauseServicesCallsCountLock = NSLock()
|
||||
private var pauseServicesUnderlyingCallsCount = 0
|
||||
var pauseServicesCallsCount: Int {
|
||||
get { pauseServicesCallsCountLock.withLock { pauseServicesUnderlyingCallsCount } }
|
||||
set { pauseServicesCallsCountLock.withLock { pauseServicesUnderlyingCallsCount = newValue } }
|
||||
}
|
||||
var pauseServicesCompletionCalled: Bool {
|
||||
return pauseServicesCompletionCallsCount > 0
|
||||
var pauseServicesCalled: Bool {
|
||||
return pauseServicesCallsCount > 0
|
||||
}
|
||||
var pauseServicesCompletionClosure: (((() -> Void)?) -> Void)?
|
||||
var pauseServicesClosure: (() async -> Void)?
|
||||
|
||||
func pauseServices(completion: (() -> Void)?) {
|
||||
pauseServicesCompletionCallsCountLock.withLock { pauseServicesCompletionUnderlyingCallsCount += 1 }
|
||||
pauseServicesCompletionClosure?(completion)
|
||||
func pauseServices() async {
|
||||
pauseServicesCallsCountLock.withLock { pauseServicesUnderlyingCallsCount += 1 }
|
||||
await pauseServicesClosure?()
|
||||
}
|
||||
//MARK: - expireSyncSessions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user