Type MethodConcurrency
sleep(until:tolerance:clock:)
Suspends the current task until the given deadline within a tolerance.
- iOS 16.0+
- macOS 13.0+
- tvOS 16.0+
- watchOS 9.0+
static func sleep<C>(until deadline: C.Instant, tolerance: C.Instant.Duration? = nil, clock: C) async throws where C : Clock
Overview
If the task is canceled before the time ends, this function throws CancellationError
.
This function doesn’t block the underlying thread.
try await Task.sleep(until: .now + .seconds(3), clock: .continuous)