Skip to content

Commit 462d444

Browse files
authored
Continuation crash (#777)
I didn't get the feedback on the actual runtime errors yet, but I believe it's still worth merging - as a decent technical change (removing `Unsafe...`). I don't see any obvious mistakes in the existing code either.
1 parent 297df56 commit 462d444

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Sources/LiveKit/Support/AsyncCompleter.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ actor CompleterMapActor<T: Sendable> {
6666
final class AsyncCompleter<T: Sendable>: @unchecked Sendable, Loggable {
6767
//
6868
struct WaitEntry {
69-
let continuation: UnsafeContinuation<T, Error>
69+
let continuation: CheckedContinuation<T, Error>
7070
let timeoutBlock: DispatchWorkItem
7171

7272
func cancel() {
@@ -123,6 +123,10 @@ final class AsyncCompleter<T: Sendable>: @unchecked Sendable, Loggable {
123123

124124
func resume(with result: Result<T, Error>) {
125125
_lock.sync {
126+
if let _result {
127+
log("\(label) already resolved \(_entries) with \(_result)", .debug)
128+
}
129+
126130
for entry in _entries.values {
127131
entry.resume(with: result)
128132
}
@@ -160,7 +164,7 @@ final class AsyncCompleter<T: Sendable>: @unchecked Sendable, Loggable {
160164

161165
// Create a cancel-aware timed continuation
162166
return try await withTaskCancellationHandler {
163-
try await withUnsafeThrowingContinuation { continuation in
167+
try await withCheckedThrowingContinuation { continuation in
164168
// Create time-out block
165169
let timeoutBlock = DispatchWorkItem { [weak self] in
166170
guard let self else { return }

0 commit comments

Comments
 (0)