-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Adds sleep(for:) to clock #61222
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
Adds sleep(for:) to clock #61222
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,18 +133,18 @@ extension Task where Success == Never, Failure == Never { | |
/// | ||
/// This function doesn't block the underlying thread. | ||
/// | ||
/// try await Task.sleep(until: .now + .seconds(3), clock: .continuous) | ||
/// try await Task.sleep(until: .now + .seconds(3)) | ||
/// | ||
@available(SwiftStdlib 5.7, *) | ||
public static func sleep<C: Clock>( | ||
until deadline: C.Instant, | ||
tolerance: C.Instant.Duration? = nil, | ||
clock: C | ||
clock: C = ContinuousClock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here w.r.t. symbols in the library. |
||
) async throws { | ||
try await clock.sleep(until: deadline, tolerance: tolerance) | ||
} | ||
|
||
/// Suspends the current task for the given duration on a continuous clock. | ||
/// Suspends the current task for the given duration. | ||
/// | ||
/// If the task is cancelled before the time ends, this function throws | ||
/// `CancellationError`. | ||
|
@@ -153,11 +153,14 @@ extension Task where Success == Never, Failure == Never { | |
/// | ||
/// try await Task.sleep(for: .seconds(3)) | ||
/// | ||
/// - Parameter duration: The duration to wait. | ||
@available(SwiftStdlib 5.7, *) | ||
@_alwaysEmitIntoClient | ||
public static func sleep(for duration: Duration) async throws { | ||
try await sleep(until: .now + duration, clock: .continuous) | ||
public static func sleep<C: Clock>( | ||
for duration: C.Instant.Duration, | ||
tolerance: C.Instant.Duration? = nil, | ||
clock: C = ContinuousClock() | ||
) async throws { | ||
try await clock.sleep(for: duration, tolerance: tolerance) | ||
} | ||
} | ||
#else | ||
|
@@ -169,13 +172,18 @@ extension Task where Success == Never, Failure == Never { | |
public static func sleep<C: Clock>( | ||
until deadline: C.Instant, | ||
tolerance: C.Instant.Duration? = nil, | ||
clock: C | ||
clock: C = ContinuousClock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that adding a default argument is not actually possible here, because the symbol that provides the default will not be available in library versions that predate the appearance of the default. @slavapestov, is that right? If so, you should instead add an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be misremembering, but I'd thought that it was the longstanding case that default arguments are emitted into the client and (thus) ABI stable to add? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, here we go: #56859 (comment) |
||
) async throws { | ||
fatalError("Unavailable in task-to-thread concurrency model") | ||
} | ||
@available(SwiftStdlib 5.7, *) | ||
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model") | ||
public static func sleep(for duration: Duration) async throws { | ||
@_alwaysEmitIntoClient | ||
public static func sleep<C: Clock>( | ||
mbrandonw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for duration: C.Instant.Duration, | ||
tolerance: C.Instant.Duration? = nil, | ||
clock: C = ContinuousClock() | ||
) async throws { | ||
fatalError("Unavailable in task-to-thread concurrency model") | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.