A Swift library providing ordered task queues for sending work from nonisolated contexts to asynchronous contexts like actors.
swift-async-queue is a Swift library that provides specialized queue types to guarantee ordered task execution when sending work from nonisolated (synchronous) contexts to asynchronous contexts in Swift Concurrency. It solves the problem of unordered task execution inherent in the standard library by ensuring predictable and serialized execution. The library includes FIFOQueue for strict first-in-first-out ordering, ActorQueue for ordered tasks sent to actors, and MainActor.queue for the main actor.
Swift developers building concurrent applications who need to ensure task ordering when transitioning from synchronous to asynchronous code, particularly those working with actors and the main actor. It is also suitable for developers requiring cancellable task queues for resource management.
Developers choose swift-async-queue because it fills gaps in Swift Concurrency by offering simple, type-safe abstractions for ordered task execution without introducing unnecessary complexity. Its integration with Swift's actor model and support for cancellation provide correctness and flexibility not readily available in the standard library.
A library of queues that enable sending ordered tasks to asynchronous contexts
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
FIFOQueue ensures tasks begin and end in exact enqueued order from nonisolated contexts, preventing race conditions where standard Swift tasks fail, as shown in the library's test examples.
ActorQueue allows ordered task sending to actors from any context, leveraging Swift's actor isolation for atomic execution between suspension points, filling a gap in the standard library.
MainActor.queue provides a built-in, ready-to-use queue for ordered task execution on the main actor, simplifying UI updates from synchronous code without manual coordination.
CancellableQueue enables cancelling all executing and pending tasks at once, useful for resource cleanup in scenarios like network request management, as demonstrated in the README example.
Tasks on a FIFOQueue that await results from the same queue will deadlock, requiring careful design to avoid recursive awaits, similar to DispatchQueue limitations that the README explicitly warns about.
ActorQueue must be tied to an actor's lifecycle with execution context set in init; misuse leads to crashes, adding error-prone boilerplate that the README admits as a strict requirement.
Focuses solely on ordered execution patterns, lacking support for concurrent queues or unordered task management, which may not suit applications needing mixed concurrency models.