$ show manolofdez/AsyncBluetooth
AsyncBluetooth is a Swift Package Manager library that brings Swift Concurrency to CoreBluetooth. It wraps the central manager and peripheral delegate APIs into async/await methods and AsyncStreams, so clients can scan, connect, discover services and characteristics, read/write values, and subscribe to notifications without nested delegate callbacks. It is not a standalone application; it is a dependency library for Apple-platform apps performing Bluetooth Low Energy central-role work. Architecturally, the code is split into CentralManager and Peripheral layers, with supporting types for scan data, services, characteristics, and events. A notable internal component is CentralManagerContext, a serialized async work queue that guarantees per-key operation ordering and supports cancellation. CoreBluetooth callbacks are translated into typed event enums such as CentralManagerEvent and exposed as AsyncStreams. The library uses os.log for diagnostics and ships a privacy manifest, indicating modern Apple platform practices. Maintenance is active: the repository has recent commits and a 6.2.2 tag. The code uses current Swift concurrency features, has no third-party dependencies, and includes tests. Technical drift is low.
The LLM identified 3 files worth highlighting for reuse:
A serialized async work queue that ensures only one Bluetooth operation per key executes at a time. It suspends on continuations, supports cancellation of queued work, and resumes clients with results. This is a self-contained concurrency primitive that could be extracted and reused in any Swift project needing ordered async tasks with per-key serialization.
Defines the typed event stream emitted by the central manager, such as scan results and connection state changes. It provides a type-safe, exhaustive API for consumers to react to CoreBluetooth callbacks via AsyncStream. The pattern of modeling asynchronous callback groups as an enum is reusable for bridging delegate-based APIs to Swift Concurrency.
Wraps CBService with async discovery of characteristics and convenience accessors. It encapsulates the CoreBluetooth discovery dance behind a clean Swift interface, making it a good example of wrapping delegate-based APIs in async/await. This pattern can be reused as a reference for similar peripheral abstraction layers in other BLE libraries.