Continuation
A mechanism to interface between synchronous and asynchronous code, which enforces that the continuation is resumed exactly once.
Declaration
@frozen struct Continuation<Success, Failure> where Failure : Error, Success : ~CopyableOverview
Unlike CheckedContinuation, which detects misuse at runtime, Continuation uses non-copyable semantics to enforce correct usage.
The continuation must only ever be resumed exactly-once. The compiler will prevent attempts from resuming the continuation more than once.
If a Continuation is destroyed without being resumed, the program traps with a diagnostic message indicating where the continuation was created. Because it is noncopyable, the compiler prevents accidental copies, and the consuming resume methods ensure the continuation can only be used once.
To create a continuation call withContinuation(of:throwing:_:).
To resume the task, suspended on a continuation, call resume(returning:), resume(throwing:), resume(with:), or resume().