Skip to content

Commit a096aee

Browse files
authored
feat: add support for returning a value to TaskQueue.sync (#2387)
1 parent e547979 commit a096aee

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Amplify/Core/Support/TaskQueue.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ public actor TaskQueue<Success> {
1212

1313
public init() {}
1414

15-
public func sync(block: @Sendable @escaping () async throws -> Success) rethrows {
16-
previousTask = Task { [previousTask] in
15+
public func sync(block: @Sendable @escaping () async throws -> Success) async throws -> Success {
16+
let currentTask = Task { [previousTask] in
1717
_ = await previousTask?.result
1818
return try await block()
1919
}
20+
previousTask = currentTask
21+
return try await currentTask.value
2022
}
2123

2224
public nonisolated func async(block: @Sendable @escaping () async throws -> Success) rethrows {

0 commit comments

Comments
 (0)