withTaskPriorityEscalationHandler(operation:onPriorityEscalated:)
Runs the passed operation while registering a task priority escalation handler. The handler will be triggered concurrently to the current task if the current is subject to priority escalation.
Declaration
nonisolated(nonsending) func withTaskPriorityEscalationHandler<T, E>(operation: nonisolated(nonsending) () async throws(E) -> T, onPriorityEscalated handler: @Sendable (TaskPriority, TaskPriority) -> Void) async throws(E) -> T where E : ErrorParameters
- operation:
The operation during which to listen for priority escalation
- handler:
Handler to invoke, concurrently to
operation, when priority escalation happens. The first argument is the old priority (before escalation), and the second argument is the new escalated priority.
Return Value
The value returned by operation
Discussion
The handler may perform additional actions upon priority escalation, but cannot influence how the escalation influences the task, i.e. the task’s priority will be escalated regardless of actions performed in the handler.
The handler will only trigger if a priority escalation occurs while the operation is in progress.
If multiple task escalation handlers are nested they will all be triggered.
Task escalation propagates through structured concurrency child-tasks.