From c731f87848ba2de5e306845110e7e50e8dc45acc Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Mon, 18 Nov 2024 10:11:12 -0300 Subject: [PATCH] =?UTF-8?q?Make=20waitForCompletionOfOperationWithID?= =?UTF-8?q?=E2=80=99s=20throw=20typed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Will use in an upcoming commit (want to add a manager method with a typed throw). --- Sources/AblyChat/RoomLifecycleManager.swift | 36 ++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Sources/AblyChat/RoomLifecycleManager.swift b/Sources/AblyChat/RoomLifecycleManager.swift index f8d1308c..433456fd 100644 --- a/Sources/AblyChat/RoomLifecycleManager.swift +++ b/Sources/AblyChat/RoomLifecycleManager.swift @@ -539,7 +539,7 @@ internal actor DefaultRoomLifecycleManager + typealias Continuation = CheckedContinuation, Never> private var operationResultContinuationsByOperationID: [UUID: [Continuation]] = [:] @@ -585,11 +585,11 @@ internal actor DefaultRoomLifecycleManager) { + private func operationWithID(_ operationID: UUID, didCompleteWithResult result: Result) { logger.log(message: "Operation \(operationID) completed with result \(result)", level: .debug) let continuationsToResume = operationResultContinuations.removeContinuationsForResultOfOperationWithID(operationID) for continuation in continuationsToResume { - continuation.resume(with: result) + continuation.resume(returning: result) } } @@ -622,16 +624,18 @@ internal actor DefaultRoomLifecycleManager( + private func performAnOperation( forcingOperationID forcedOperationID: UUID?, - _ body: (UUID) async throws(Failure) -> Void - ) async throws(Failure) { + _ body: (UUID) async throws(ARTErrorInfo) -> Void + ) async throws(ARTErrorInfo) { let operationID = forcedOperationID ?? UUID() logger.log(message: "Performing operation \(operationID)", level: .debug) - let result: Result + let result: Result do { // My understanding (based on what the compiler allows me to do, and a vague understanding of how actors work) is that inside this closure you can write code as if it were a method on the manager itself — i.e. with synchronous access to the manager’s state. But I currently lack the Swift concurrency vocabulary to explain exactly why this is the case. try await body(operationID) @@ -660,12 +664,12 @@ internal actor DefaultRoomLifecycleManager