MCPcopy Index your code
hub / github.com/al8n/wg

github.com/al8n/wg @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
84 symbols 199 edges 10 files 18 documented · 21%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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?

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.

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

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

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

  • Inspired by Go's sync.WaitGroup and [crossbeam_utils::WaitGroup].

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.

Extension points exported contracts — how you extend this code

Mu (Interface)
(no doc) [2 implementers]
src/sync.rs

Core symbols most depended-on inside this repo

add
called by 26
src/spin.rs
done
called by 21
src/spin.rs
clone
called by 19
src/spin.rs
wait
called by 19
src/spin.rs
lock_me
called by 5
src/sync.rs
wait_blocking
called by 2
src/future.rs
clone
called by 1
src/future.rs
add
called by 1
src/future.rs

Shape

Function 44
Method 33
Class 6
Interface 1

Languages

Rust100%

Modules by API surface

tests/future.rs25 symbols
src/sync.rs14 symbols
src/future.rs14 symbols
src/spin.rs13 symbols
tests/sync.rs8 symbols
tests/spin.rs6 symbols
tests/send_sync.rs2 symbols
examples/sync.rs1 symbols
examples/future.rs1 symbols

For agents

$ claude mcp add wg \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact