Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ Your operation sees the [task-local values](https://developer.apple.com/document
- A task runs at the priority you pass to `Task(on:)`. If you pass `nil`, it runs at the priority of the code that enqueues it, as with `Task.init`.
- `FIFOQueue(priority:)` gives each of the queue's tasks at least that priority. A task that would run at a lower priority runs at the queue's priority instead.
- When a higher-priority task awaits a task's value, Swift raises, or *escalates*, that task's priority, as it does for any task.
- On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later, a task that waits in a queue also raises the priority of the tasks ahead of it to its own priority. That way, the tasks ahead of a high-priority task don't run at a lower priority while it waits. On earlier releases, the tasks ahead keep their own priority.
- A task keeps a raised priority until it finishes.

### Cancellation

Expand Down
20 changes: 20 additions & 0 deletions Sources/AsyncQueue/ActorQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished or suspended.
Expand Down Expand Up @@ -136,6 +140,7 @@ extension Task {
await turn.begin()
return await execute(operation, on: executionContext, endingTurn: turn)
}
turn.register(self)
}

/// Runs the given throwing operation asynchronously
Expand All @@ -145,6 +150,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished or suspended.
Expand Down Expand Up @@ -176,6 +185,7 @@ extension Task {
await turn.begin()
return try await execute(operation, on: executionContext, endingTurn: turn)
}
turn.register(self)
}

/// Runs the given nonthrowing operation asynchronously
Expand All @@ -185,6 +195,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished or suspended.
Expand Down Expand Up @@ -215,6 +229,7 @@ extension Task {
await turn.begin()
return await executeOnMainActor(operation, endingTurn: turn)
}
turn.register(self)
}

/// Runs the given throwing operation asynchronously
Expand All @@ -224,6 +239,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished or suspended.
Expand Down Expand Up @@ -254,6 +273,7 @@ extension Task {
await turn.begin()
return try await executeOnMainActor(operation, endingTurn: turn)
}
turn.register(self)
}
}

Expand Down
32 changes: 32 additions & 0 deletions Sources/AsyncQueue/CancellableQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished or suspended.
Expand Down Expand Up @@ -194,6 +198,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished or suspended.
Expand Down Expand Up @@ -237,6 +245,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished or suspended.
Expand Down Expand Up @@ -280,6 +292,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished or suspended.
Expand Down Expand Up @@ -324,6 +340,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished.
Expand Down Expand Up @@ -369,6 +389,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished.
Expand Down Expand Up @@ -414,6 +438,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished.
Expand Down Expand Up @@ -461,6 +489,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished.
Expand Down
20 changes: 20 additions & 0 deletions Sources/AsyncQueue/FIFOQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished.
Expand Down Expand Up @@ -117,6 +121,7 @@ extension Task {
defer { turn.end() }
return await operation()
}
turn.register(self)
}

/// Runs the given throwing operation asynchronously
Expand All @@ -127,6 +132,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished.
Expand Down Expand Up @@ -159,6 +168,7 @@ extension Task {
defer { turn.end() }
return try await operation()
}
turn.register(self)
}

/// Runs the given nonthrowing operation asynchronously
Expand All @@ -169,6 +179,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished.
Expand Down Expand Up @@ -203,6 +217,7 @@ extension Task {
defer { turn.end() }
return await operation(isolatedActor)
}
turn.register(self)
}

/// Runs the given throwing operation asynchronously
Expand All @@ -213,6 +228,10 @@ extension Task {
/// Like a task created with `Task.init(name:priority:operation:)`, the task inherits the task-local values
/// and, unless you pass a `priority`, the priority of the code that enqueues it.
/// When a higher-priority task awaits the task's value, Swift escalates the task's priority.
/// On Linux, and on macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26 or later,
/// a task that waits on the queue also escalates the tasks ahead of it to its own priority.
/// On earlier releases, the tasks ahead keep their own priority.
/// An escalated task keeps that priority until it finishes.
///
/// Cancelling the task doesn't remove it from the queue: the operation still runs,
/// after every task enqueued before it has finished.
Expand Down Expand Up @@ -247,5 +266,6 @@ extension Task {
defer { turn.end() }
return try await operation(isolatedActor)
}
turn.register(self)
}
}
Loading
Loading