<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Task/sleep(for:tolerance:clock:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:ScT12_Concurrencys5NeverORszACRs_rlE5sleep3for9tolerance5clocky8DurationQyd___AISgqd__tYaKAA5ClockRd__lFZ"
  },
  "title" : "sleep(for:tolerance:clock:)"
}
-->

# sleep(for:tolerance:clock:)

Suspends the current task for the given duration.

```
static func sleep<C>(for duration: C.Instant.Duration, 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(for: .seconds(3))
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)