🚀 First 1.0.0 Semver-stable release 1.0.0 of swift-dispatch-async - a pure-swift implementation of libDispatch
swift-dispatch-async is a lightweight Swift package providing core Grand Central Dispatch (GCD)–APIs implemented using Swift Concurrency. Pure Swift, no direct C or Posix library usage.
Designed to provide support for Swift for WebAssembly / WASI, where the standard Dispatch library has been previously unavailable.
🎯 Overview
- Implements a minimal compatibility layer for
DispatchAPIs using async/await. - Enables Swift for WebAssembly builds without modifying code that depends on GCD. You can just replace
import Dispatchwithimport DispatchAsyncfor most cases.
✅ Features
DispatchQueue- Supports
DispatchQueue.main,DispatchQueue.global(), and custom queues. - Provides
async(_:)for asynchronous task submission using Swift Concurrency.
- Supports
DispatchWorkItem- Lightweight wrapper for units of concurrent work.
- Can be submitted to queues or executed directly via async tasks.
DispatchTime/DispatchWallTime- Minimal support for scheduling and time-based operations.
DispatchSemaphore- Async-safe, non-blocking implementation for single-threaded WASM environments.
- Balanced
waitandsignalrequired; assertions enforce correctness.
- Conditional Import Support
- Seamless replacement for
Dispatchwhen unavailable:#if os(WASI) && !canImport(Dispatch) import DispatchAsync #else import Dispatch #endif
- Seamless replacement for
- Cross-Platform Test Suite
- Includes tests ported from the original libDispatch project.
- Validates queue behavior, async scheduling, and semaphore semantics.
- SwiftPM Integration & Apache-2.0 License
📓 Notes
- Blocking APIs (e.g.
sync) are not supported by design. DispatchSemaphoreassumes single-threaded execution on WASM.- Any unavoidable breaking API changes will be created following traditional semver rules with a bump in the major version of the package.