Skip to content

Initial Release

Compare
Choose a tag to compare
@swhitty swhitty released this 20 May 01:48
· 72 commits to main since this release
aad418d

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

Usage is similar to existing continuations:

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

The continuation includes an id that can be attached to an asynchronous task enabling the onCancel handler to cancel it.

let val: String? = await withIdentifiableContinuation { continuation in
  foo.startTask(for: continuation.id) { result
     continuation.resume(returning: result)
  }
} onCancel: { id in
  foo.cancelTask(for: id)
}