Initializerswift 6.0.1_Concurrency
init(priority:operation:)
Runs the given throwing operation asynchronously as part of a new top-level task on behalf of the current actor.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
@discardableResult init(priority: TaskPriority? = nil, operation: sending @escaping @isolated(any) () async throws -> Success)
Parameters
Use this function when creating asynchronous work that operates on behalf of the synchronous function that calls it. Like Task.detached(priority:operation:)
, this function creates a separate, top-level task. Unlike detach(priority:operation:)
, the task created by Task.init(priority:operation:)
inherits the priority and actor context of the caller, so the operation is treated more like an asynchronous extension to the synchronous operation.
You need to keep a reference to the task if you want to cancel it by calling the Task.cancel()
method. Discarding your reference to a detached task doesn’t implicitly cancel that task, it only makes it impossible for you to explicitly cancel the task.
Other members in extension
Type members
init(executorPreference: consuming (any TaskExecutor)?, priority: TaskPriority?, operation: sending
Runs the given throwing operation asynchronously as part of a new top-level task on behalf of the current actor.
static func detached(executorPreference: (any TaskExecutor)?, priority: TaskPriority?, operation: sending
Runs the given throwing operation asynchronously as part of a new top-level task.
static func detached(priority: TaskPriority?, operation: sending
Runs the given throwing operation asynchronously as part of a new top-level task.