Contents

sleep(until:tolerance:clock:)

Suspends the current task until the given deadline within a tolerance.

Declaration

static func sleep<C>(until deadline: C.Instant, tolerance: C.Instant.Duration? = nil, clock: C = .continuous) async throws where C : Clock

Discussion

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))

See Also

Suspending Execution