Skip to content

Commit

Permalink
#function
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Apr 14, 2024
1 parent a8b22e4 commit 374f722
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions FlyingSocks/Sources/IdentifiableContinuation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
@_spi(Private)
public func withIdentifiableContinuation<T>(
isolation: isolated some Actor,
function: String = #function,
body: (IdentifiableContinuation<T, Never>) -> Void,
onCancel handler: @Sendable (IdentifiableContinuation<T, Never>.ID) -> Void
) async -> T {
let id = IdentifiableContinuation<T, Never>.ID()
let state = AllocatedLock(initialState: (isStarted: false, isCancelled: false))
return await withTaskCancellationHandler {
await withCheckedContinuation {
await withCheckedContinuation(function: function) {
let continuation = IdentifiableContinuation(id: id, continuation: $0)
body(continuation)
let sendCancel = state.withLock {
Expand Down Expand Up @@ -90,13 +91,14 @@ public func withIdentifiableContinuation<T>(
@_spi(Private)
public func withIdentifiableThrowingContinuation<T>(
isolation: isolated some Actor,
function: String = #function,
body: (IdentifiableContinuation<T, any Error>) -> Void,
onCancel handler: @Sendable (IdentifiableContinuation<T, any Error>.ID) -> Void
) async throws -> T {
let id = IdentifiableContinuation<T, any Error>.ID()
let state = AllocatedLock(initialState: (isStarted: false, isCancelled: false))
return try await withTaskCancellationHandler {
try await withCheckedThrowingContinuation {
try await withCheckedThrowingContinuation(function: function) {
let continuation = IdentifiableContinuation(id: id, continuation: $0)
body(continuation)
let sendCancel = state.withLock {
Expand Down

0 comments on commit 374f722

Please sign in to comment.