@@ -86,7 +86,6 @@ struct IdentifiableContinuationTests {
86
86
let waiter = Waiter < String ? , Never > ( )
87
87
88
88
let task = await waiter. makeTask ( delay: 1.0 , onCancel: nil )
89
- try ? await Task . sleep ( seconds: 0.1 )
90
89
let isEmpty = await waiter. isEmpty
91
90
#expect( isEmpty)
92
91
task. cancel ( )
@@ -160,7 +159,6 @@ struct IdentifiableContinuationTests {
160
159
let waiter = Waiter < String ? , any Error > ( )
161
160
162
161
let task = await waiter. makeTask ( delay: 1.0 , onCancel: . failure( CancellationError ( ) ) )
163
- try ? await Task . sleep ( seconds: 0.1 )
164
162
let isEmpty = await waiter. isEmpty
165
163
#expect( isEmpty)
166
164
task. cancel ( )
@@ -181,42 +179,58 @@ private actor Waiter<T: Sendable, E: Error> {
181
179
waiting. isEmpty
182
180
}
183
181
184
- func makeTask( delay: TimeInterval = 0 , onCancel: T ) -> Task < T , Never > where E == Never {
182
+ func makeTask( delay: TimeInterval , onCancel: T ) -> Task < T , Never > where E == Never {
185
183
Task {
186
184
try ? await Task . sleep ( seconds: delay)
187
- #if compiler(>=6.0)
188
185
return await withIdentifiableContinuation {
189
186
addContinuation ( $0)
190
187
} onCancel: { id in
191
188
Task { await self . resumeID ( id, returning: onCancel) }
192
189
}
193
- #else
194
- return await withIdentifiableContinuation ( isolation: self ) {
190
+ }
191
+ }
192
+
193
+ func makeTask( onCancel: T ) async -> Task < T , Never > where E == Never {
194
+ nonisolated ( unsafe) var continuation : CheckedContinuation < Void , Never > !
195
+ let task = Task {
196
+ return await withIdentifiableContinuation {
195
197
addContinuation ( $0)
198
+ continuation. resume ( )
196
199
} onCancel: { id in
197
200
Task { await self . resumeID ( id, returning: onCancel) }
198
201
}
199
- #endif
200
202
}
203
+ await withCheckedContinuation {
204
+ continuation = $0
205
+ }
206
+ return task
201
207
}
202
208
203
- func makeTask( delay: TimeInterval = 0 , onCancel: Result < T , E > ) -> Task < T , any Error > where E == any Error {
209
+ func makeTask( delay: TimeInterval , onCancel: Result < T , E > ) -> Task < T , any Error > where E == any Error {
204
210
Task {
205
211
try ? await Task . sleep ( seconds: delay)
206
- #if compiler(>=6.0)
207
212
return try await withIdentifiableThrowingContinuation {
208
213
addContinuation ( $0)
209
214
} onCancel: { id in
210
215
Task { await self . resumeID ( id, with: onCancel) }
211
216
}
212
- #else
213
- return try await withIdentifiableThrowingContinuation ( isolation: self ) {
217
+ }
218
+ }
219
+
220
+ func makeTask( onCancel: Result < T , E > ) async -> Task < T , any Error > where E == any Error {
221
+ nonisolated ( unsafe) var continuation : CheckedContinuation < Void , Never > !
222
+ let task = Task {
223
+ try await withIdentifiableThrowingContinuation {
214
224
addContinuation ( $0)
225
+ continuation. resume ( )
215
226
} onCancel: { id in
216
227
Task { await self . resumeID ( id, with: onCancel) }
217
228
}
218
- #endif
219
229
}
230
+ await withCheckedContinuation {
231
+ continuation = $0
232
+ }
233
+ return task
220
234
}
221
235
222
236
private func addContinuation( _ continuation: Continuation ) {
0 commit comments