wg provides three WaitGroup flavors so you can pick the right synchronization
primitive for the context you're in — blocking, async, or lock-free — all with
the same add / done / wait / remaining surface.
wg follows Semantic Versioning and has a deliberately
narrow scope: three WaitGroup variants (blocking, async, lock-free). The API
is considered complete for that scope. Bug fixes, documentation improvements,
and small non-breaking additions (trait impls, ergonomic tweaks) are welcome;
new features outside the WaitGroup concept are out of scope — use a different
primitive.
| Type | When to use | Backed by |
|---|---|---|
wg::WaitGroup |
Default choice for synchronous code on std. Blocks the calling thread in wait. |
Mutex + Condvar (or parking_lot equivalents) |
wg::future::WaitGroup |
Async contexts (also support no_std + alloc environments). Works with any async runtime (tokio, smol, …). Exposes wait().await plus a wait_blocking() escape hatch. |
event-listener |
wg::spin::WaitGroup |
no_std + alloc environments, or short waits where you want to avoid OS synchronization. |
AtomicUsize with adaptive backoff (yields on std, spins on pure no_std) |
All three implement Clone, Debug, Send + Sync, and From<usize>. API is
otherwise identical — easy to switch between variants.
Default build (blocking WaitGroup, std, parking_lot, triomphe):
[dependencies]
wg = "1"Enable the async variant (wg::future::WaitGroup):
[dependencies]
wg = { version = "1", features = ["future"] }no_std + alloc build (only wg::spin::WaitGroup and, with future, wg::future::WaitGroup):
[dependencies]
wg = { version = "1", default-features = false, features = ["alloc"] }
# + async:
wg = { version = "1", default-features = false, features = ["alloc", "future"] }| Feature | Default | Description |
|---|---|---|
std |
yes | Enables the blocking wg::WaitGroup (uses std::sync). |
parking_lot |
yes | Switches the blocking variant to parking_lot::{Mutex, Condvar}. |
triomphe |
yes | Uses triomphe::Arc (no weak refs, smaller footprint). |
alloc |
no | Required in no_std builds to use spin::WaitGroup / future::WaitGroup. |
future |
no | Enables wg::future::WaitGroup (event-listener based). |
See examples/ for more.
Minimum supported Rust version is 1.76.0. This is dictated by the current
parking_lot and triomphe minima; enabling neither feature would drop the
floor further. MSRV bumps are considered a breaking change and will require a
major version bump.
- Inspired by Go's
sync.WaitGroupandcrossbeam_utils::WaitGroup.
wg is under the terms of both the MIT license and the
Apache License (Version 2.0).
See LICENSE-APACHE, LICENSE-MIT for details.
Copyright (c) 2026 Al Liu.