@@ -128,12 +128,12 @@ import Swift
128
128
/// - Throws: if the operation closure throws
129
129
/// - SeeAlso: ``TaskExecutor``
130
130
@_unavailableInEmbedded
131
- @available ( SwiftStdlib 9999 , * )
132
- @_unsafeInheritExecutor // calling withTaskExecutor MUST NOT perform the "usual" hop to global
133
- public func withTaskExecutorPreference< T: Sendable > (
131
+ @available ( SwiftStdlib 6 . 0 , * )
132
+ public func withTaskExecutorPreference< T, Failure> (
134
133
_ taskExecutor: ( any TaskExecutor ) ? ,
135
- operation: @Sendable ( ) async throws -> T
136
- ) async rethrows -> T {
134
+ isolation: isolated ( any Actor ) ? = #isolation,
135
+ operation: ( ) async throws ( Failure ) -> T
136
+ ) async throws ( Failure) -> T {
137
137
guard let taskExecutor else {
138
138
// User explicitly passed a "nil" preference, so we invoke the operation
139
139
// as is, which will hop to it's expected executor without any change in
@@ -159,9 +159,32 @@ public func withTaskExecutorPreference<T: Sendable>(
159
159
return try await operation ( )
160
160
}
161
161
162
+ @_unavailableInEmbedded
163
+ @available ( SwiftStdlib 6 . 0 , * )
164
+ @_unsafeInheritExecutor // calling withTaskExecutor MUST NOT perform the "usual" hop to global
165
+ @_silgen_name ( " $ss26withTaskExecutorPreference_9operationxSch_pSg_xyYaYbKXEtYaKs8SendableRzlF " )
166
+ public func __abi__withTaskExecutorPreference< T: Sendable > (
167
+ _ taskExecutor: ( any TaskExecutor ) ? ,
168
+ operation: @Sendable ( ) async throws -> T
169
+ ) async rethrows -> T {
170
+ guard let taskExecutor else {
171
+ return try await operation ( )
172
+ }
173
+
174
+ let taskExecutorBuiltin : Builtin . Executor =
175
+ taskExecutor. asUnownedTaskExecutor ( ) . executor
176
+
177
+ let record = _pushTaskExecutorPreference ( taskExecutorBuiltin)
178
+ defer {
179
+ _popTaskExecutorPreference ( record: record)
180
+ }
181
+
182
+ return try await operation ( )
183
+ }
184
+
162
185
/// Task with specified executor -----------------------------------------------
163
186
164
- @available ( SwiftStdlib 9999 , * )
187
+ @available ( SwiftStdlib 6 . 0 , * )
165
188
extension Task where Failure == Never {
166
189
/// Runs the given nonthrowing operation asynchronously
167
190
/// as part of a new top-level task on behalf of the current actor.
@@ -227,7 +250,7 @@ extension Task where Failure == Never {
227
250
}
228
251
}
229
252
230
- @available ( SwiftStdlib 9999 , * )
253
+ @available ( SwiftStdlib 6 . 0 , * )
231
254
extension Task where Failure == Error {
232
255
/// Runs the given throwing operation asynchronously
233
256
/// as part of a new top-level task on behalf of the current actor.
@@ -289,7 +312,7 @@ extension Task where Failure == Error {
289
312
290
313
// ==== Detached tasks ---------------------------------------------------------
291
314
292
- @available ( SwiftStdlib 9999 , * )
315
+ @available ( SwiftStdlib 6 . 0 , * )
293
316
extension Task where Failure == Never {
294
317
/// Runs the given nonthrowing operation asynchronously
295
318
/// as part of a new top-level task.
@@ -346,7 +369,7 @@ extension Task where Failure == Never {
346
369
}
347
370
}
348
371
349
- @available ( SwiftStdlib 9999 , * )
372
+ @available ( SwiftStdlib 6 . 0 , * )
350
373
extension Task where Failure == Error {
351
374
/// Runs the given throwing operation asynchronously
352
375
/// as part of a new top-level task.
@@ -407,7 +430,7 @@ extension Task where Failure == Error {
407
430
408
431
// ==== Unsafe Current Task ----------------------------------------------------
409
432
410
- @available ( SwiftStdlib 9999 , * )
433
+ @available ( SwiftStdlib 6 . 0 , * )
411
434
extension UnsafeCurrentTask {
412
435
413
436
/// The current ``TaskExecutor`` preference, if this task has one configured.
@@ -417,7 +440,7 @@ extension UnsafeCurrentTask {
417
440
/// The lifetime of an executor is not guaranteed by an ``UnownedTaskExecutor``,
418
441
/// so accessing it must be handled with great case -- and the program must use other
419
442
/// means to guarantee the executor remains alive while it is in use.
420
- @available ( SwiftStdlib 9999 , * )
443
+ @available ( SwiftStdlib 6 . 0 , * )
421
444
public var unownedTaskExecutor : UnownedTaskExecutor ? {
422
445
let ref = _getPreferredTaskExecutor ( )
423
446
return UnownedTaskExecutor ( ref)
@@ -426,18 +449,18 @@ extension UnsafeCurrentTask {
426
449
427
450
// ==== Runtime ---------------------------------------------------------------
428
451
429
- @available ( SwiftStdlib 9999 , * )
452
+ @available ( SwiftStdlib 6 . 0 , * )
430
453
@_silgen_name ( " swift_task_getPreferredTaskExecutor " )
431
454
internal func _getPreferredTaskExecutor( ) -> Builtin . Executor
432
455
433
456
typealias TaskExecutorPreferenceStatusRecord = UnsafeRawPointer
434
457
435
- @available ( SwiftStdlib 9999 , * )
458
+ @available ( SwiftStdlib 6 . 0 , * )
436
459
@_silgen_name ( " swift_task_pushTaskExecutorPreference " )
437
460
internal func _pushTaskExecutorPreference( _ executor: Builtin . Executor )
438
461
-> TaskExecutorPreferenceStatusRecord
439
462
440
- @available ( SwiftStdlib 9999 , * )
463
+ @available ( SwiftStdlib 6 . 0 , * )
441
464
@_silgen_name ( " swift_task_popTaskExecutorPreference " )
442
465
internal func _popTaskExecutorPreference(
443
466
record: TaskExecutorPreferenceStatusRecord
@@ -447,7 +470,7 @@ internal func _popTaskExecutorPreference(
447
470
///
448
471
/// It can be used to compare against, and is semantically equivalent to
449
472
/// "no preference".
450
- @available ( SwiftStdlib 9999 , * )
473
+ @available ( SwiftStdlib 6 . 0 , * )
451
474
@usableFromInline
452
475
internal func _getUndefinedTaskExecutor( ) -> Builtin . Executor {
453
476
// Similar to the `_getGenericSerialExecutor` this method relies
0 commit comments