Repository navigation
Each Task(on:) now runs its operation in the task it returns, so the operation inherits the task-local values and priority of the code that enqueues it, and awaiting the task escalates it, just like Task. 2.0 requires Swift 6.4 and the OS releases that ship Synchronization.Mutex.
Breaking changes
- Requirements. Swift tools 6.4 (Xcode 27). Minimum platforms are macOS 15, iOS 18, tvOS 18, watchOS 11, Mac Catalyst 18 and visionOS 2. (#88)
name:queue initializers removed.ActorQueue(name:)andFIFOQueue(name:priority:)named an internal task that no longer exists. UseActorQueue()/ActorQueue(priority:)andFIFOQueue(priority:); to name a task, useTask(name:on:). (#91, #92)- Operations run at the enqueuing code's priority. In 1.x,
ActorQueueoperations ran at the priority of the code that created the queue, and aFIFOQueuewithout a priority ran everything at.medium. Now an operation enqueued from.backgroundcode runs at.background.
Migration: to keep a floor, create the queue withFIFOQueue(priority: .medium)orActorQueue(priority: .medium), or enqueue withTask(priority:on:).MainActor.queuehas no floor, so useTask(priority:on:)there too. (#91, #92, #97) - Operations see the enqueuing code's task-local values. In 1.x they saw the values bound when the queue was created; for
MainActor.queue, that was the first caller's values for the life of the process.
Migration: bind task-local values where you enqueue, not where you create the queue. (#91, #92)
New
FIFOQueue.isIdleandActorQueue.hasStartedAllWork, to tell when a queue you created on demand can be removed. (#96)ActorQueue(priority:)gives every task on the queue at least that priority, likeFIFOQueue(priority:). (#97)- A task waiting for its turn raises the priority of the task ahead of it on macOS/iOS/tvOS/watchOS/visionOS 26+ and Linux, so a
.hightask no longer waits at.backgroundspeed. On anActorQueue, an escalated task's work after its first suspension was already free to overtake earlier tasks' work, and escalation makes that more likely. (#94) Task(priority:on:)now works with aCancellableQueue<FIFOQueue>. Before, onlyTask(priority:on:isolatedTo:)took a priority there. (#93)
Fixes
ActorQueuetasks enqueued with mixed priorities now start in enqueue order. (#91)- Awaiting a task returned by
Task(on:)now escalates its operation. (#91, #92) Task(priority:on:)on aFIFOQueuenow runs at that priority; three of its four initializers ignored it. (#92)cancelTasks()now cancels tasks that are still being enqueued, including a task whose own operation callscancelTasks(). (#90)
Performance
- Per-task overhead on Linux:
ActorQueueabout 15 µs → 9 µs,FIFOQueueabout 25 µs → 4 µs. (#91, #92) - Tasks on
MainActor.queue(or anyActorQueue<MainActor>), andFIFOQueueandCancellableQueue<FIFOQueue>tasks whose operation runs on the main actor, start directly on the main actor instead of hopping there from the global executor, when no earlier task is still waiting. Enqueuing and awaiting these tasks is about 25–35% faster. As a result, such a task now runs before aTask { @MainActor in … }created after it. (#101) - Locks use
Mutexinstead of serial dispatch queues, andCancellableQueuebookkeeping happens synchronously instead of throughDispatchQueue.async. (#89)
Other
- Documentation and README rewritten to say exactly how ordering, task-local values, priority and cancellation work. (#93, #100)
- CI runs Thread Sanitizer on macOS and tests on the iOS 18 simulator; every test is deterministic and runs once. (#99)
Full Changelog: 1.1.2...2.0.0