1. 2022-8-9
    2. 2022-7-25
    Type MethodConcurrency

    sleep(for:)

    Suspends the current task for the given duration on a continuous clock.

    • Available when Success is Never and Failure is Never

    • iOS 16.0+
    • macOS 13.0+
    • tvOS 16.0+
    • watchOS 9.0+
    static func sleep(for duration: Duration) async throws

    Parameters

    duration

    The duration to wait.

    Overview

    If the task is cancelled before the time ends, this function throws CancellationError.

    This function doesn’t block the underlying thread.

      try await Task.sleep(for: .seconds(3))