Structure_Concurrency5.9.0
UnsafeCurrentTask
An unsafe reference to the current task.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
struct UnsafeCurrentTask
To get an instance of UnsafeCurrentTask
for the current task, call the withUnsafeCurrentTask(body:)
method. Don’t store an unsafe task reference for use outside that method’s closure. Storing an unsafe reference doesn’t affect the task’s actual life cycle, and the behavior of accessing an unsafe task reference outside of the withUnsafeCurrentTask(body:)
method’s closure isn’t defined.
Only APIs on UnsafeCurrentTask
that are also part of Task
are safe to invoke from a task other than the task that this UnsafeCurrentTask
instance refers to. Calling other APIs from another task is undefined behavior, breaks invariants in other parts of the program running on this task, and may lead to crashes or data loss.
For information about the language-level concurrency model that UnsafeCurrentTask
is part of, see Concurrency in The Swift Programming Language.
Citizens in _Concurrency
Conformances
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.
Members
var basePriority: TaskPriority
The current task’s base priority.
var isCancelled: Bool
A Boolean value that indicates whether the current task was canceled.
var priority: TaskPriority
The current task’s priority.
static func == (UnsafeCurrentTask, UnsafeCurrentTask
) -> Bool func cancel(
) Cancel the current task.
func hash(into: inout Hasher
)