@@ -182,11 +182,11 @@ public actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
182
182
private let executionStateChangedCallback : ( @Sendable ( QueuedTask, TaskExecutionState) async -> Void ) ?
183
183
184
184
init(
185
- priority: TaskPriority ? = nil ,
185
+ priority: TaskPriority ,
186
186
description: TaskDescription ,
187
187
executionStateChangedCallback: ( @Sendable ( QueuedTask, TaskExecutionState) async -> Void ) ?
188
188
) async {
189
- self . _priority = AtomicUInt8 ( initialValue: priority? . rawValue ?? Task . currentPriority . rawValue)
189
+ self . _priority = AtomicUInt8 ( initialValue: priority. rawValue)
190
190
self . description = description
191
191
self . executionStateChangedCallback = executionStateChangedCallback
192
192
@@ -277,6 +277,10 @@ public actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
277
277
" Elevating priority of \( self . description. forLogging) from \( self . priority. rawValue) to \( targetPriority. rawValue) "
278
278
)
279
279
}
280
+ // Awaiting the result task from a higher-priority task will eventually update `priority` through
281
+ // `withTaskPriorityChangedHandler` but that might take a while because `withTaskPriorityChangedHandler` polls.
282
+ // Since we know that the priority will be elevated, set it now. That way we don't try to elevate it again.
283
+ self . priority = targetPriority
280
284
Task ( priority: targetPriority) {
281
285
await self . resultTask. value
282
286
}
@@ -352,7 +356,7 @@ public actor TaskScheduler<TaskDescription: TaskDescriptionProtocol> {
352
356
) ? = nil
353
357
) async -> QueuedTask < TaskDescription > {
354
358
let queuedTask = await QueuedTask (
355
- priority: priority,
359
+ priority: priority ?? Task . currentPriority ,
356
360
description: taskDescription,
357
361
executionStateChangedCallback: executionStateChangedCallback
358
362
)
0 commit comments