Skip to content

2.0.0

Latest

Choose a tag to compare

@dfed dfed released this 17 Nov 03:31
ccbfc26

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:) and FIFOQueue(name:priority:) named an internal task that no longer exists. Use ActorQueue() / ActorQueue(priority:) and FIFOQueue(priority:); to name a task, use Task(name:on:). (#91, #92)
  • Operations run at the enqueuing code's priority. In 1.x, ActorQueue operations ran at the priority of the code that created the queue, and a FIFOQueue without a priority ran everything at .medium. Now an operation enqueued from .background code runs at .background.
    Migration: to keep a floor, create the queue with FIFOQueue(priority: .medium) or ActorQueue(priority: .medium), or enqueue with Task(priority:on:). MainActor.queue has no floor, so use Task(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.isIdle and ActorQueue.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, like FIFOQueue(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 .high task no longer waits at .background speed. On an ActorQueue, 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 a CancellableQueue<FIFOQueue>. Before, only Task(priority:on:isolatedTo:) took a priority there. (#93)

Fixes

  • ActorQueue tasks 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 a FIFOQueue now 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 calls cancelTasks(). (#90)

Performance

  • Per-task overhead on Linux: ActorQueue about 15 µs → 9 µs, FIFOQueue about 25 µs → 4 µs. (#91, #92)
  • Tasks on MainActor.queue (or any ActorQueue<MainActor>), and FIFOQueue and CancellableQueue<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 a Task { @MainActor in … } created after it. (#101)
  • Locks use Mutex instead of serial dispatch queues, and CancellableQueue bookkeeping happens synchronously instead of through DispatchQueue.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