<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/withContinuation(of:throwing:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:12_Concurrency16withContinuation2of8throwing_xxm_q_myAA0C0Vyxq_GnXEtYaq_YKs5ErrorR_Ri_zr0_lF"
  },
  "title" : "withContinuation(of:throwing:_:)"
}
-->

# withContinuation(of:throwing:_:)

Invokes the passed in closure with a non-copyable continuation for the current task.

```
nonisolated(nonsending) func withContinuation<Success, Failure>(of: Success.Type = Success.self, throwing: Failure.Type, _ body: (consuming Continuation<Success, Failure>) -> Void) async throws(Failure) -> sending Success where Failure : Error, Success : ~Copyable
```

## Parameters

`of`

The `Success` type returned by the continuation

`throwing`

The `Failure` type that may be thrown

`body`

A closure that takes a `Continuation` parameter

## Return Value

The value the 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.
The continuation is a noncopyable type, and therefore multiple resume
calls are prevented at compile time (as resuming the continuation
consumes it). However, if the continuation is dropped without being
resumed, the program traps.

---

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)