Skip to main content

Crate asyncband

Crate asyncband 

Source
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.

§Release status

Version 0.7.1 is an interim non-ASF release. It has not been approved by the Apache Incubator PMC and is not an act of the Apache Software Foundation.

§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

AreaAPIFeatureUse
Shared stateMutexmutexProtect shared data with asynchronous mutual exclusion.
RwLockrwlockAllow multiple readers or one writer.
CondvarcondvarWait for notifications while releasing a mutex.
Initialization and cachingOnceonceComplete one asynchronous initialization; cancelled or panicked attempts may be retried.
OnceCellonce-cellStore one value from an access-time initializer; failed, cancelled, or panicked attempts may be retried.
LazyCelllazy-cellInitialize one value with a stored function and resume the same in-flight future after caller cancellation.
OnceMaponce-mapCache one successfully initialized value per key until explicitly removed.
Task coordinationBarrierbarrierSynchronize a fixed number of participants at a reusable rendezvous.
CompletioncompletionPublish one shared result to any number of current and future observers.
ManualResetEventeventSignal current and future waits until explicitly reset.
LatchlatchWait until a fixed one-way countdown reaches zero.
WaitGroupwaitgroupDynamically register participants and wait until all have completed.
ShutdownshutdownRequest shutdown and wait until all completion guards are dropped.
ChannelsoneshotoneshotSend one value from one sender to one receiver.
mpscmpscSend each value from multiple producers to one receiver with bounded backpressure or an unbounded queue.
broadcastbroadcastDeliver every value to receivers active at send time; retain an unbounded backlog until each consumes or drops.
watchwatchPublish the latest state to independently tracked receivers and coalesce intermediate updates.
Resource reusepoolpoolReuse objects through bounded or unbounded pool variants.
Concurrency limitingSemaphoresemaphoreLimit concurrent work by acquiring permits.
Duplicate suppressionGroupsingleflightCoalesce overlapping calls for the same key without caching completed results.
Sync interopFutureExtblockingDrive 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’s single-future executor parks the calling thread and resumes it through the future’s waker. 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§

barrierbarrier
Synchronize a fixed number of tasks at a reusable rendezvous point.
blockingblocking
Synchronous interoperability for runtime-agnostic futures.
broadcastbroadcast
Broadcast channels grouped by producer topology.
completioncompletion
A shared one-shot completion primitive.
condvarcondvar
A condition variable that allows tasks to wait for a notification.
eventevent
A reusable, level-triggered signal for coordinating tasks.
latchlatch
Wait for a one-way countdown to reach zero.
mpscmpsc
Multi-producer, single-consumer channels for asynchronous tasks.
mutexmutex
An async mutex for protecting shared data.
oncelazy-cell or once-cell or once-map or once
Asynchronous primitives for one-time coordination.
oneshotoneshot
A one-shot channel is used for sending a single message between asynchronous tasks. The channel function is used to create a Sender and Receiver pair that form the channel.
poolpool
Runtime-agnostic object pools for async Rust.
rwlockrwlock
A reader-writer lock that allows multiple readers or a single writer at a time.
semaphoresemaphore
Limit concurrent access with a set of permits.
shutdownshutdown
Coordination primitives for graceful task shutdown.
singleflightsingleflight
Coalesce concurrent work that uses the same key.
waitgroupwaitgroup
Coordinate completion across a dynamically sized group of participants.
watchwatch
A channel that retains and distributes the latest state.