Expand description
Composable, runtime-agnostic concurrency building blocks for async Rust.
asyncband provides synchronization, initialization, task coordination, channels, resource
reuse, and workload control without choosing an executor for the application. Its async APIs use
standard futures and wakers, so they can run on Tokio, async-std, smol, or a custom executor.
§Getting started
Public APIs are enabled through opt-in Cargo features, and no features are enabled by default. Enable the APIs your application needs:
asyncband = { version = "0.7", features = ["mutex", "oneshot"] }Then use the selected APIs directly:
use asyncband::mutex::Mutex;
let counter = Mutex::new(0);
{
let mut value = counter.lock().await;
*value += 1;
}
assert_eq!(*counter.lock().await, 1);§API map
| Area | API | Feature | Use |
|---|---|---|---|
| Locks and conditions | Mutex | mutex | Protect shared data with asynchronous mutual exclusion. |
RwLock | rwlock | Allow multiple readers or one writer. | |
Condvar | condvar | Wait for notifications while releasing a mutex. | |
| Coordination | Semaphore | semaphore | Limit concurrent work by acquiring permits. |
Barrier | barrier | Synchronize a fixed number of participants at a reusable rendezvous. | |
ManualResetEvent | event | Signal current and future waits until explicitly reset. | |
AutoResetEvent | event | Retain one signal and release one waiter per consumed signal. | |
Latch | latch | Wait until a fixed one-way countdown reaches zero. | |
Phaser | phaser | Coordinate repeated phases with a dynamic participant set. | |
WaitGroup | waitgroup | Dynamically register participants and wait until all have completed. | |
Shutdown | shutdown | Request shutdown and wait until all completion guards are dropped. | |
| Work coalescing | Once | once | Complete one asynchronous initialization; cancelled or panicked attempts may be retried. |
OnceCell | once-cell | Store one value from an access-time initializer; failed, cancelled, or panicked attempts may be retried. | |
LazyCell | lazy-cell | Initialize one value with a stored function and resume the same in-flight future after caller cancellation. | |
OnceMap | once-map | Coalesce work per key and retain each successful value until explicitly removed. | |
Group | singleflight | Coalesce overlapping work per key without retaining completed values. | |
| Communication | Completion | completion | Publish one shared result to any number of current and future observers. |
oneshot | oneshot | Send one value from one sender to one receiver. | |
mpmc | mpmc | Distribute each value to exactly one of multiple competing receivers. | |
mpsc | mpsc | Send each value from multiple producers to one receiver with bounded backpressure or an unbounded queue. | |
spmc | spmc | Distribute work from one exclusive sender to multiple competing receivers, with bounded or unbounded storage. | |
broadcast | broadcast | Deliver every value to active receivers with bounded backpressure or unbounded retention. | |
watch | watch | Publish cloneable latest state from one or more senders; receivers independently coalesce intermediate updates. | |
| Object reuse | pool | pool | Reuse objects through bounded or unbounded pool variants. |
| Sync interop | FutureExt | blocking | Drive one runtime-agnostic future from a blocking thread. |
§Scope and runtime model
The project is not limited to small or stateless primitives. Stateful tools such as
singleflight::Group and the pool module fit when they provide reusable coordination and
remain independent of executor policy.
The async APIs do not start threads, spawn tasks, install timers, or require a runtime-specific reactor. Task placement, deadlines, retries, periodic maintenance, and lifecycle orchestration remain with the caller. Await Asyncband futures inside any executor that polls standard Rust futures, and compose those runtime services around them.
§Async first, blocking by adaptation
Async and synchronous primitives have different optimization constraints. Asyncband designs its
primitives for async use and provides the optional blocking module as a boundary adapter
instead of duplicating synchronous methods across every type. Sync-first implementations can
exploit OS- or platform-specific facilities and remain the domain of dedicated libraries.
The adapter polls one future on the calling thread. It is not a general-purpose async runtime, and futures that depend on a runtime-specific timer or I/O driver may not make progress. See the module documentation for the full execution constraints.
§Thread safety
Asyncband types implement Send and Sync only when their protected, transferred, or managed
values satisfy the required bounds. Consult each API’s documentation for its exact contract.
§Disclaimer
Apache Asyncband (Incubating) is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Apache Incubator PMC.
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision-making process have stabilized in a manner consistent with other successful ASF projects.
While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
Modules§
- barrier
barrier - Synchronize a fixed number of tasks at a reusable rendezvous point.
- blocking
blocking - Synchronous interoperability for runtime-agnostic futures.
- broadcast
broadcast - Broadcast channels grouped by producer topology.
- completion
completion - A shared one-shot completion primitive.
- condvar
condvar - A condition variable that allows tasks to wait for a notification.
- event
event - Reusable signals for coordinating tasks without carrying a value.
- latch
latch - Wait for a one-way countdown to reach zero.
- mpmc
mpmc - A multi-producer, multi-consumer queue for sending values between asynchronous tasks.
- mpsc
mpsc - Multi-producer, single-consumer channels for asynchronous tasks.
- mutex
mutex - Mutual exclusion that yields the current task while waiting.
- once
lazy-celloronce-celloronce-maporonce - Asynchronous primitives for one-time coordination.
- oneshot
oneshot - A one-shot channel is used for sending a single message between asynchronous tasks. The
channelfunction is used to create aSenderandReceiverpair that form the channel. - phaser
phaser - Coordinate repeated rounds of work with a dynamic participant set.
- pool
pool - Runtime-agnostic object pools for async Rust.
- rwlock
rwlock - Shared read access or exclusive write access to a value.
- semaphore
semaphore - Limit concurrent access with a set of permits.
- shutdown
shutdown - Coordination primitives for graceful task shutdown.
- singleflight
singleflight - Coalesce concurrent work that uses the same key.
- spmc
spmc - Single-producer, multi-consumer queues for distributing work between asynchronous tasks.
- waitgroup
waitgroup - Coordinate completion across a dynamically sized group of participants.
- watch
watch - A channel that retains and distributes the latest state.