Skip to content

[Concurrency] Add *Continuation.resume() for continuations returning Void. #35829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions stdlib/public/Concurrency/CheckedContinuation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ public struct CheckedContinuation<T> {
}
}

extension CheckedContinuation where T == Void {
/// Resume the task awaiting the continuation by having it return normally
/// from its suspension point.
///
/// A continuation must be resumed exactly once. If the continuation has
/// already been resumed through this object, then the attempt to resume
/// the continuation again will trap.
///
/// After `resume` enqueues the task, control is immediately returned to
/// the caller. The task will continue executing when its executor is
/// able to reschedule it.
@inlinable
public func resume() {
self.resume(returning: ())
}
}

public func withCheckedContinuation<T>(
function: String = #function,
_ body: (CheckedContinuation<T>) -> Void
Expand Down Expand Up @@ -244,6 +261,23 @@ public struct CheckedThrowingContinuation<T> {
}
}

extension CheckedThrowingContinuation where T == Void {
/// Resume the task awaiting the continuation by having it return normally
/// from its suspension point.
///
/// A continuation must be resumed exactly once. If the continuation has
/// already been resumed through this object, then the attempt to resume
/// the continuation again will trap.
///
/// After `resume` enqueues the task, control is immediately returned to
/// the caller. The task will continue executing when its executor is
/// able to reschedule it.
@inlinable
public func resume() {
self.resume(returning: ())
}
}

public func withCheckedThrowingContinuation<T>(
function: String = #function,
_ body: (CheckedThrowingContinuation<T>) -> Void
Expand Down
14 changes: 14 additions & 0 deletions stdlib/public/Concurrency/PartialAsyncTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public struct UnsafeContinuation<T> {
public func resume(returning value: __owned T)
}

extension UnsafeContinuation where T == Void {
@inlinable
public func resume() {
self.resume(returning: ())
}
}

@frozen
public struct UnsafeThrowingContinuation<T> {
@usableFromInline internal var context: Builtin.RawUnsafeContinuation
Expand All @@ -58,6 +65,13 @@ public struct UnsafeThrowingContinuation<T> {
}
}

extension UnsafeThrowingContinuation where T == Void {
@inlinable
public func resume() {
self.resume(returning: ())
}
}

#if _runtime(_ObjC)

// Intrinsics used by SILGen to resume or fail continuations
Expand Down