Skip to content

Commit 7fdc65d

Browse files
authored
Merge pull request #35793 from jckarter/checked-continuation-resume-with-result
CheckedContinuation: Add `resume(with: Result)` for parity with UnsafeContinuation
2 parents 2d2a810 + 35802bf commit 7fdc65d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

stdlib/public/Concurrency/CheckedContinuation.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,26 @@ public struct CheckedThrowingContinuation<T> {
242242
fatalError("SWIFT TASK CONTINUATION MISUSE: \(canary.function) tried to resume its continuation more than once, throwing \(x)!\n")
243243
}
244244
}
245+
246+
/// Resume the task awaiting the continuation by having it either
247+
/// return normally or throw an error based on the state of the given
248+
/// `Result` value.
249+
///
250+
/// A continuation must be resumed exactly once. If the continuation has
251+
/// already been resumed through this object, then the attempt to resume
252+
/// the continuation again will trap.
253+
///
254+
/// After `resume` enqueues the task, control is immediately returned to
255+
/// the caller. The task will continue executing when its executor is
256+
/// able to reschedule it.
257+
public func resume<E: Error>(with x: __owned Result<T, E>) {
258+
switch x {
259+
case .success(let s):
260+
return resume(returning: s)
261+
case .failure(let e):
262+
return resume(throwing: e)
263+
}
264+
}
245265
}
246266

247267
public func withCheckedThrowingContinuation<T>(

0 commit comments

Comments
 (0)