44
44
/// - body: A closure that takes a `IdentifiableContinuation` parameter.
45
45
/// - handler: Cancellation closure executed when the current Task is cancelled. Handler is always called _after_ the body closure is compeled.
46
46
/// - Returns: The value continuation is resumed with.
47
+ @inlinable
47
48
package func withIdentifiableContinuation< T> (
48
49
isolation: isolated ( any Actor ) ? = #isolation,
49
50
function: String = #function,
50
51
body: ( IdentifiableContinuation < T , Never > ) -> Void ,
51
52
onCancel handler: @Sendable ( IdentifiableContinuation < T , Never > . ID ) -> Void
52
53
) async -> T {
53
54
let id = IdentifiableContinuation < T , Never > . ID ( )
54
- let state = AllocatedLock ( initialState : ( isStarted: false , isCancelled: false ) )
55
+ let state = Mutex ( ( isStarted: false , isCancelled: false ) )
55
56
nonisolated ( unsafe) let body = body
56
57
return await withTaskCancellationHandler {
57
58
await withCheckedContinuation ( isolation: isolation, function: function) {
@@ -90,14 +91,15 @@ package func withIdentifiableContinuation<T>(
90
91
/// - body: A closure that takes a `IdentifiableContinuation` parameter.
91
92
/// - handler: Cancellation closure executed when the current Task is cancelled. Handler is always called _after_ the body closure is compeled.
92
93
/// - Returns: The value continuation is resumed with.
94
+ @inlinable
93
95
package func withIdentifiableThrowingContinuation< T> (
94
96
isolation: isolated ( any Actor ) ? = #isolation,
95
97
function: String = #function,
96
98
body: ( IdentifiableContinuation < T , any Error > ) -> Void ,
97
99
onCancel handler: @Sendable ( IdentifiableContinuation < T , any Error > . ID ) -> Void
98
100
) async throws -> T {
99
101
let id = IdentifiableContinuation < T , any Error > . ID ( )
100
- let state = AllocatedLock ( initialState : ( isStarted: false , isCancelled: false ) )
102
+ let state = Mutex ( ( isStarted: false , isCancelled: false ) )
101
103
nonisolated ( unsafe) let body = body
102
104
return try await withTaskCancellationHandler {
103
105
try await withCheckedThrowingContinuation ( isolation: isolation, function: function) {
@@ -138,14 +140,15 @@ package func withIdentifiableThrowingContinuation<T>(
138
140
/// - handler: Cancellation closure executed when the current Task is cancelled. Handler is always called _after_ the body closure is compeled.
139
141
/// - Returns: The value continuation is resumed with.
140
142
@_unsafeInheritExecutor
143
+ @inlinable
141
144
package func withIdentifiableContinuation< T> (
142
145
isolation: isolated some Actor ,
143
146
function: String = #function,
144
147
body: ( IdentifiableContinuation < T , Never > ) -> Void ,
145
148
onCancel handler: @Sendable ( IdentifiableContinuation < T , Never > . ID ) -> Void
146
149
) async -> T {
147
150
let id = IdentifiableContinuation < T , Never > . ID ( )
148
- let state = AllocatedLock ( initialState : ( isStarted: false , isCancelled: false ) )
151
+ let state = Mutex ( ( isStarted: false , isCancelled: false ) )
149
152
return await withTaskCancellationHandler {
150
153
await withCheckedContinuation ( function: function) {
151
154
let continuation = IdentifiableContinuation ( id: id, continuation: $0)
@@ -186,14 +189,15 @@ package func withIdentifiableContinuation<T>(
186
189
/// - handler: Cancellation closure executed when the current Task is cancelled. Handler is always called _after_ the body closure is compeled.
187
190
/// - Returns: The value continuation is resumed with.
188
191
@_unsafeInheritExecutor
192
+ @inlinable
189
193
package func withIdentifiableThrowingContinuation< T> (
190
194
isolation: isolated some Actor ,
191
195
function: String = #function,
192
196
body: ( IdentifiableContinuation < T , any Error > ) -> Void ,
193
197
onCancel handler: @Sendable ( IdentifiableContinuation < T , any Error > . ID ) -> Void
194
198
) async throws -> T {
195
199
let id = IdentifiableContinuation < T , any Error > . ID ( )
196
- let state = AllocatedLock ( initialState : ( isStarted: false , isCancelled: false ) )
200
+ let state = Mutex ( ( isStarted: false , isCancelled: false ) )
197
201
return try await withTaskCancellationHandler {
198
202
try await withCheckedThrowingContinuation ( function: function) {
199
203
let continuation = IdentifiableContinuation ( id: id, continuation: $0)
@@ -219,23 +223,30 @@ package func withIdentifiableThrowingContinuation<T>(
219
223
}
220
224
#endif
221
225
226
+ @usableFromInline
222
227
package struct IdentifiableContinuation < T, E> : Sendable , Identifiable where E: Error {
223
228
229
+ @usableFromInline
224
230
package let id : ID
225
231
232
+ @usableFromInline
226
233
package final class ID : Hashable , Sendable {
227
234
235
+ @usableFromInline
228
236
init ( ) { }
229
237
238
+ @usableFromInline
230
239
package func hash( into hasher: inout Hasher ) {
231
240
ObjectIdentifier ( self ) . hash ( into: & hasher)
232
241
}
233
242
243
+ @usableFromInline
234
244
package static func == ( lhs: IdentifiableContinuation < T , E > . ID , rhs: IdentifiableContinuation < T , E > . ID ) -> Bool {
235
245
lhs === rhs
236
246
}
237
247
}
238
248
249
+ @usableFromInline
239
250
init ( id: ID , continuation: CheckedContinuation < T , E > ) {
240
251
self . id = id
241
252
self . continuation = continuation
0 commit comments