<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/withCheckedContinuation(function:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:12_Concurrency23withCheckedContinuation8function_xSS_yScCyxs5NeverOGXEtYalF"
  },
  "title" : "withCheckedContinuation(function:_:)"
}
-->

# withCheckedContinuation(function:_:)

Invokes the passed in closure with a checked continuation for the current task.

```
@abi(nonisolated(nonsending) func withCheckedContinuationNonisolatedNonsending<T>(function: String, _ body: (CheckedContinuation<T, Never>) -> Void) async -> sending T) nonisolated(nonsending) func withCheckedContinuation<T>(function: String = #function, _ body: (CheckedContinuation<T, Never>) -> Void) async -> sending T
```

## Parameters

`function`

A string identifying the declaration that is the notional
source for the continuation, used to identify the continuation in
runtime diagnostics related to misuse of this continuation.

`body`

A closure that takes a `CheckedContinuation` parameter.

## Return Value

The value continuation is resumed with.

## Discussion

The body of the closure executes synchronously on the calling task, and once it returns
the calling task is suspended. It is possible to immediately resume the task, or escape the
continuation in order to complete it afterwards, which will then resume the suspended task.

You must invoke the continuation’s `resume` method exactly once.

Missing to invoke it (eventually) will cause the calling task to remain suspended
indefinitely which will result in the task “hanging” as well as being leaked with
no possibility to destroy it.

The checked continuation offers detection of misuse, and dropping the last reference
to it, without having resumed it will trigger a warning. Resuming a continuation twice
is also diagnosed and will cause a crash.

> SeeAlso: `withCheckedThrowingContinuation(function:_:)`

> SeeAlso: `withUnsafeContinuation(function:_:)`

> SeeAlso: `withUnsafeThrowingContinuation(function:_:)`

---

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)