TaskExecutor
An executor that may be used as preferred executor by a task.
- iOS
- 18.0+
- macOS
- 15.0+
- tvOS
- 18.0+
- visionOS
- 2.0+
- watchOS
- 11.0+
protocol TaskExecutor : ExecutorBrowse conforming typesImpact of setting a task executor preference
By default, without setting a task executor preference, nonisolated asynchronous functions, as well as methods declared on default actors – that is actors which do not require a specific executor – execute on Swift’s default global concurrent executor. This is an executor shared by the entire runtime to execute any work which does not have strict executor requirements.
By setting a task executor preference, either with a withTaskExecutorPreference(_:operation:), creating a task with a preference (Task(executorPreference:), or group.addTask(executorPreference:)), the task and all of its child tasks (unless a new preference is set) will be preferring to execute on the provided task executor.
Unstructured tasks do not inherit the task executor.