Swift continuation that conforms to Identifiable and includes a cancellation handler.

What's New

Preserve calling #function


Preserves calling #function passing it to the inner CheckedContinuation allowing for better diagnostics.

Build Codecov Platforms Swift 5.10 License Twitter


IdentifiableContinuation is a lightweight wrapper around CheckedContinuation that conforms to Identifiable and includes an easy to use cancellation handler with the id.


IdentifiableContinuation can be installed by using Swift Package Manager.

Note: IdentifiableContinuation requires Swift 5.7 on Xcode 14+. It runs on iOS 13+, tvOS 13+, macOS 10.15+, Linux and Windows. To install using Swift Package Manager, add this to the dependencies: section in your Package.swift file:

.package(url: "", .upToNextMajor(from: "0.1.0"))


Usage is similar to existing continuations, but requires an Actor to ensure the closure is executed within the actors isolation:

let val: String = await withIdentifiableContinuation(isolation: self) { 
    $0.resume(returning: "bar")

This allows actors to synchronously start continuations and mutate their isolated state before suspension occurs. The onCancel: handler is @Sendable and can be called at any time after the body has completed. Manually check Task.isCancelled before creating the continuation to prevent performing unrequired work.

let val: String = await withIdentifiableContinuation(isolation: self) {
  // executed within actor isolation so can immediatley mutate actor state
  continuations[$] = $0
} onCancel: { id in
  // @Sendable closure executed outside of actor isolation requires `await` to mutate actor state
  Task { await self.cancelContinuation(with: id) }


IdentifiableContinuation is primarily the work of Simon Whitty.

(Full list of contributors)


  • Swift Tools 5.8.0
View More Packages from this Author


  • None
Last updated: Sun Jul 14 2024 08:03:40 GMT-0900 (Hawaii-Aleutian Daylight Time)