Skip to main content

Crate wg

Crate wg 

Source
Expand description

wg

Golang like WaitGroup implementation for sync/async Rust, support no_std environment.

github LoC Build codecov

docs.rs crates.io crates.io license

§Introduction

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.

§Status

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.

§Which WaitGroup should I use?

TypeWhen to useBacked by
wg::WaitGroupDefault choice for synchronous code on std. Blocks the calling thread in wait.Mutex + Condvar (or parking_lot equivalents)
wg::future::WaitGroupAsync 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::WaitGroupno_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.

§Installation

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 flags

FeatureDefaultDescription
stdyesEnables the blocking wg::WaitGroup (uses std::sync).
parking_lotyesSwitches the blocking variant to parking_lot::{Mutex, Condvar}.
triompheyesUses triomphe::Arc (no weak refs, smaller footprint).
allocnoRequired in no_std builds to use spin::WaitGroup / future::WaitGroup.
futurenoEnables wg::future::WaitGroup (event-listener based).

§Examples

See examples/ for more.

§MSRV

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.

§Acknowledgements

§License

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.

Modules§

future(std or alloc) and future
A WaitGroup that can be used in async contexts. See future::WaitGroup for details.
spinstd or alloc
A lock-free, atomic-counter WaitGroup that spins on wait.

Structs§

WaitGroupstd
A WaitGroup waits for a collection of threads to finish.