Skip to content

Commit 5db55aa

Browse files
committed
Add *Continuation.resume() for continuations returning Void.
This change implements the changes proposed in swift-evolution PR #1264. Existing test coverage should be sufficient here since the added function simply calls into the existing `resume(returning:)` function. This change resolves rdar://74031110.
1 parent 7fe3187 commit 5db55aa

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

stdlib/public/Concurrency/CheckedContinuation.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,22 @@ public struct CheckedContinuation<T> {
151151
}
152152
}
153153

154+
extension CheckedContinuation where T == Void {
155+
/// Resume the task awaiting the continuation by having it return normally
156+
/// from its suspension point.
157+
///
158+
/// A continuation must be resumed exactly once. If the continuation has
159+
/// already been resumed through this object, then the attempt to resume
160+
/// the continuation again will trap.
161+
///
162+
/// After `resume` enqueues the task, control is immediately returned to
163+
/// the caller. The task will continue executing when its executor is
164+
/// able to reschedule it.
165+
public func resume() {
166+
self.resume(returning: ())
167+
}
168+
}
169+
154170
public func withCheckedContinuation<T>(
155171
function: String = #function,
156172
_ body: (CheckedContinuation<T>) -> Void
@@ -244,6 +260,22 @@ public struct CheckedThrowingContinuation<T> {
244260
}
245261
}
246262

263+
extension CheckedThrowingContinuation where T == Void {
264+
/// Resume the task awaiting the continuation by having it return normally
265+
/// from its suspension point.
266+
///
267+
/// A continuation must be resumed exactly once. If the continuation has
268+
/// already been resumed through this object, then the attempt to resume
269+
/// the continuation again will trap.
270+
///
271+
/// After `resume` enqueues the task, control is immediately returned to
272+
/// the caller. The task will continue executing when its executor is
273+
/// able to reschedule it.
274+
public func resume() {
275+
self.resume(returning: ())
276+
}
277+
}
278+
247279
public func withCheckedThrowingContinuation<T>(
248280
function: String = #function,
249281
_ body: (CheckedThrowingContinuation<T>) -> Void

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public struct UnsafeContinuation<T> {
3434
public func resume(returning value: __owned T)
3535
}
3636

37+
extension UnsafeContinuation where T == Void {
38+
public func resume() {
39+
self.resume(returning: ())
40+
}
41+
}
42+
3743
@frozen
3844
public struct UnsafeThrowingContinuation<T> {
3945
@usableFromInline internal var context: Builtin.RawUnsafeContinuation
@@ -58,6 +64,12 @@ public struct UnsafeThrowingContinuation<T> {
5864
}
5965
}
6066

67+
extension UnsafeThrowingContinuation where T == Void {
68+
public func resume() {
69+
self.resume(returning: ())
70+
}
71+
}
72+
6173
#if _runtime(_ObjC)
6274

6375
// Intrinsics used by SILGen to resume or fail continuations

0 commit comments

Comments
 (0)