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
Tasks created this way are **immediately enqueued** on given executor.
344
344
345
+
It is possible to pass `nil` to all task executor accepting APIs introduced in this proposal. Passing `nil` to an `executorPreference:` parameter means "no preference", and for structured tasks means to inherit the surrounding context's executor preference; and for unstructured tasks (`Task.init`, `Task.detached`) it serves as a way of documenting no specific executor preference was selected for this task. In both cases, passing `nil` is equivalent to calling the methods which do not accept an executor preference.
346
+
345
347
By default, serial executors are not task executors, and therefore cannot be directly used with these APIs.
346
348
This is because it would cause confusion in the runtime about having two "mutual exclusion" contexts at the same time, which could result in difficult to understand behaviors.
347
349
@@ -370,7 +372,10 @@ however isolation is still guaranteed by the actor's semantics:
370
372
let anywhere = RunsAnywhere()
371
373
Task { await anywhere.hello() } // runs on "default executor", using a thread from the global pool
372
374
373
-
Task(executorPreference: myExecutor) { await anywhere.hello() } // runs on preferred executor, using a thread owned by that executor
375
+
Task(executorPreference: myExecutor) {
376
+
// runs on preferred executor, using a thread owned by that executor
377
+
await anywhere.hello()
378
+
}
374
379
```
375
380
376
381
Methods which assert isolation, such as `Actor/assumeIsolated` and similar still function as expected.
@@ -684,12 +689,13 @@ In other words, task executor preference gives control to developers at when and
684
689
685
690
The defaultof hop-avoiding when a preference issetis also a good default because it optimizes for less context switching and can lead to better performance.
686
691
687
-
It is possible to disable a preference by setting the preference to `nil`. So if we want to make sure that some code would not be influenced by a caller's preference, we can defensively insert the following:
692
+
It is possible to effectively restore the default behavior as-if no task executor preference was present, by setting the preference to the `globalConcurrentExecutor` which is the executor used by default actors, tasks, and free async functions when no task executor preferenceisset:
688
693
689
694
```swift
690
695
funcfunction() async {
691
-
// make sure to ignore caller's task executor preference
692
-
awaitwithTaskExecutorPreference(nil) { ... }
696
+
// make sure to ignore caller's task executor preference,
0 commit comments