4444/// - body: A closure that takes a `IdentifiableContinuation` parameter.
4545/// - handler: Cancellation closure executed when the current Task is cancelled. Handler is always called _after_ the body closure is compeled.
4646/// - Returns: The value continuation is resumed with.
47+ @inlinable
4748package func withIdentifiableContinuation< T> (
4849 isolation: isolated ( any Actor ) ? = #isolation,
4950 function: String = #function,
5051 body: ( IdentifiableContinuation < T , Never > ) -> Void ,
5152 onCancel handler: @Sendable ( IdentifiableContinuation < T , Never > . ID ) -> Void
5253) async -> T {
5354 let id = IdentifiableContinuation < T , Never > . ID ( )
54- let state = AllocatedLock ( initialState : ( isStarted: false , isCancelled: false ) )
55+ let state = Mutex ( ( isStarted: false , isCancelled: false ) )
5556 nonisolated ( unsafe) let body = body
5657 return await withTaskCancellationHandler {
5758 await withCheckedContinuation ( isolation: isolation, function: function) {
@@ -90,14 +91,15 @@ package func withIdentifiableContinuation<T>(
9091/// - body: A closure that takes a `IdentifiableContinuation` parameter.
9192/// - handler: Cancellation closure executed when the current Task is cancelled. Handler is always called _after_ the body closure is compeled.
9293/// - Returns: The value continuation is resumed with.
94+ @inlinable
9395package func withIdentifiableThrowingContinuation< T> (
9496 isolation: isolated ( any Actor ) ? = #isolation,
9597 function: String = #function,
9698 body: ( IdentifiableContinuation < T , any Error > ) -> Void ,
9799 onCancel handler: @Sendable ( IdentifiableContinuation < T , any Error > . ID ) -> Void
98100) async throws -> T {
99101 let id = IdentifiableContinuation < T , any Error > . ID ( )
100- let state = AllocatedLock ( initialState : ( isStarted: false , isCancelled: false ) )
102+ let state = Mutex ( ( isStarted: false , isCancelled: false ) )
101103 nonisolated ( unsafe) let body = body
102104 return try await withTaskCancellationHandler {
103105 try await withCheckedThrowingContinuation ( isolation: isolation, function: function) {
@@ -138,14 +140,15 @@ package func withIdentifiableThrowingContinuation<T>(
138140/// - handler: Cancellation closure executed when the current Task is cancelled. Handler is always called _after_ the body closure is compeled.
139141/// - Returns: The value continuation is resumed with.
140142@_unsafeInheritExecutor
143+ @inlinable
141144package func withIdentifiableContinuation< T> (
142145 isolation: isolated some Actor ,
143146 function: String = #function,
144147 body: ( IdentifiableContinuation < T , Never > ) -> Void ,
145148 onCancel handler: @Sendable ( IdentifiableContinuation < T , Never > . ID ) -> Void
146149) async -> T {
147150 let id = IdentifiableContinuation < T , Never > . ID ( )
148- let state = AllocatedLock ( initialState : ( isStarted: false , isCancelled: false ) )
151+ let state = Mutex ( ( isStarted: false , isCancelled: false ) )
149152 return await withTaskCancellationHandler {
150153 await withCheckedContinuation ( function: function) {
151154 let continuation = IdentifiableContinuation ( id: id, continuation: $0)
@@ -186,14 +189,15 @@ package func withIdentifiableContinuation<T>(
186189/// - handler: Cancellation closure executed when the current Task is cancelled. Handler is always called _after_ the body closure is compeled.
187190/// - Returns: The value continuation is resumed with.
188191@_unsafeInheritExecutor
192+ @inlinable
189193package func withIdentifiableThrowingContinuation< T> (
190194 isolation: isolated some Actor ,
191195 function: String = #function,
192196 body: ( IdentifiableContinuation < T , any Error > ) -> Void ,
193197 onCancel handler: @Sendable ( IdentifiableContinuation < T , any Error > . ID ) -> Void
194198) async throws -> T {
195199 let id = IdentifiableContinuation < T , any Error > . ID ( )
196- let state = AllocatedLock ( initialState : ( isStarted: false , isCancelled: false ) )
200+ let state = Mutex ( ( isStarted: false , isCancelled: false ) )
197201 return try await withTaskCancellationHandler {
198202 try await withCheckedThrowingContinuation ( function: function) {
199203 let continuation = IdentifiableContinuation ( id: id, continuation: $0)
@@ -219,23 +223,30 @@ package func withIdentifiableThrowingContinuation<T>(
219223}
220224#endif
221225
226+ @usableFromInline
222227package struct IdentifiableContinuation < T, E> : Sendable , Identifiable where E: Error {
223228
229+ @usableFromInline
224230 package let id : ID
225231
232+ @usableFromInline
226233 package final class ID : Hashable , Sendable {
227234
235+ @usableFromInline
228236 init ( ) { }
229237
238+ @usableFromInline
230239 package func hash( into hasher: inout Hasher ) {
231240 ObjectIdentifier ( self ) . hash ( into: & hasher)
232241 }
233242
243+ @usableFromInline
234244 package static func == ( lhs: IdentifiableContinuation < T , E > . ID , rhs: IdentifiableContinuation < T , E > . ID ) -> Bool {
235245 lhs === rhs
236246 }
237247 }
238248
249+ @usableFromInline
239250 init ( id: ID , continuation: CheckedContinuation < T , E > ) {
240251 self . id = id
241252 self . continuation = continuation
0 commit comments