You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// await ActorWithCustomExecutor().hello() // 'hello' executes on actor's custom executor
41
+
///
42
+
/// // child tasks execute on default executor:
43
+
/// async let x = ...
44
+
/// await withTaskGroup(of: Int.self) { group in g.addTask { 7 } }
45
+
///
46
+
/// await withTaskExecutor(specific) {
47
+
/// // case 1) 'specific' task executor preference
48
+
///
49
+
/// // 'specific' task executor
50
+
/// // ...
51
+
/// await SomeDefaultActor().hello() // 'hello' executes on 'specific' executor
52
+
/// await ActorWithCustomExecutor().hello() // 'hello' executes on actor's custom executor (same as case 0)
53
+
///
54
+
/// // child tasks execute on 'specific' task executor:
55
+
/// async let x = ...
56
+
/// await withTaskGroup(of: Int.self) { group in g.addTask { 7 } }
57
+
///
58
+
/// // disable the task executor preference:
59
+
/// await withTaskExecutor(.default) {
60
+
/// // equivalent to case 0) preference is "default"
61
+
///
62
+
/// // default task executor
63
+
/// // ...
64
+
/// await SomeDefaultActor().hello() // default executor (same as case 0)
65
+
/// await ActorWithCustomExecutor().hello() // 'hello' executes on actor's custom executor (same as case 0)
66
+
///
67
+
/// // child tasks execute on default executor (same as case 0):
68
+
/// async let x = ...
69
+
/// await withTaskGroup(of: Int.self) { group in g.addTask { 7 } }
70
+
/// }
71
+
/// }
72
+
/// }
73
+
///
32
74
/// - Parameters:
33
-
/// - executor: the task executor to use as preferred task executor; if `nil` it is interpreted as "no preference"
75
+
/// - executorPreference: the task executor to use as preferred task executor; if `nil` it is interpreted as "no preference"
34
76
/// - operation: the operation to execute on the passed executor; if the executor was `nil`, this will execute on the default global concurrent executor.
35
77
/// - Returns: the value returned from the `operation` closure
36
78
/// - Throws: if the operation closure throws
@@ -39,22 +81,11 @@ import Swift
39
81
@available(SwiftStdlib 9999,*)
40
82
@_unsafeInheritExecutor // calling withTaskExecutor MUST NOT perform the "usual" hop to global
41
83
publicfunc _withTaskExecutor<T:Sendable>(
42
-
_ executor:(any_TaskExecutor)?,
84
+
_ taskExecutorPreference:any_TaskExecutor,
43
85
operation:@Sendable()asyncthrows->T
44
86
)asyncrethrows->T{
45
87
lettaskExecutorBuiltin:Builtin.Executor=
46
-
iflet executor {
47
-
// We need to go through the asUnowned... for serial executors,
48
-
// because they encode certain behavior in the reference bits,
49
-
// so we cannot just cast and assume it'll be correct.
50
-
executor.asUnownedTaskExecutor().executor
51
-
}else{
52
-
// we must push a "no preference" record onto the task
53
-
// because there may be other records issuing a preference already,
54
-
// so by pushing this "no preference" (undefined task executor),
55
-
// we turn off the task executor preference for the scope of `operation`.
0 commit comments