Structure_Concurrency5.9.0
TaskPriority
The priority of a task.
- iOS
- 13.0+
- macOS
- 10.15+
- tvOS
- 13.0+
- watchOS
- 6.0+
struct TaskPriority
The executor determines how priority information affects the way tasks are scheduled. The behavior varies depending on the executor currently being used. Typically, executors attempt to run tasks with a higher priority before tasks with a lower priority. However, the semantics of how priority is treated are left up to each platform and Executor
implementation.
Child tasks automatically inherit their parent task’s priority. Detached tasks created by detach(priority:operation:)
don’t inherit task priority because they aren’t attached to the current task.
In some situations the priority of a task is elevated — that is, the task is treated as it if had a higher priority, without actually changing the priority of the task:
If a task runs on behalf of an actor, and a new higher-priority task is enqueued to the actor, then the actor’s current task is temporarily elevated to the priority of the enqueued task. This priority elevation allows the new task to be processed at the priority it was enqueued with.
If a a higher-priority task calls the
get()
method, then the priority of this task increases until the task completes.
In both cases, priority elevation helps you prevent a low-priority task from blocking the execution of a high priority task, which is also known as priority inversion.
Citizens in _Concurrency
Conformances
protocol Comparable
A type that can be compared using the relational operators
<
,<=
,>=
, and>
.protocol CustomStringConvertible
A type with a customized textual representation.
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol RawRepresentable
A type that can be converted to and from an associated raw value.
protocol Sendable
A type whose values can safely be passed across concurrency domains by copying.
Members
init?(JobPriority
) Convert this
UnownedJob.Priority
to aTaskPriority
.init(rawValue: UInt8
) static let background: TaskPriority
static let high: TaskPriority
static let low: TaskPriority
static var medium: TaskPriority
static let userInitiated: TaskPriority
static let utility: TaskPriority
var description: String
var rawValue: UInt8
static func != (TaskPriority, TaskPriority
) -> Bool static func < (TaskPriority, TaskPriority
) -> Bool static func <= (TaskPriority, TaskPriority
) -> Bool static func == (TaskPriority, TaskPriority
) -> Bool static func > (TaskPriority, TaskPriority
) -> Bool static func >= (TaskPriority, TaskPriority
) -> Bool typealias RawValue
static let `default`: TaskPriority
static var unspecified: TaskPriority
static var userInteractive: TaskPriority
Features
init(from: Decoder
) throws Creates a new instance by decoding from the given decoder, when the type’s
RawValue
isUInt8
.static func != (Self, Self
) -> Bool static func ... (Self
) -> PartialRangeFrom<Self> Returns a partial range extending upward from a lower bound.
static func ... (Self
) -> PartialRangeThrough<Self> Returns a partial range up to, and including, its upper bound.
static func ... (Self, Self
) -> ClosedRange<Self> Returns a closed range that contains both of its bounds.
static func ..< (Self
) -> PartialRangeUpTo<Self> Returns a partial range up to, but not including, its upper bound.
static func ..< (Self, Self
) -> Range<Self> Returns a half-open range that contains its lower bound but not its upper bound.
func encode(to: Encoder
) throws Encodes this value into the given encoder, when the type’s
RawValue
isUInt8
.