Skip to content

Commit

Permalink
Publish 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Apr 27, 2024
1 parent 7e1dca4 commit 1c8bd57
Show file tree
Hide file tree
Showing 12 changed files with 659 additions and 898 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ jobs:
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
run: rustup update stable --no-self-update && rustup default stable
- name: Test
run: cargo test --lib --no-default-features --features future
run: cargo test --lib --features future

tokio:
name: tokio
no_std:
name: no_std
strategy:
matrix:
os:
Expand All @@ -104,8 +104,23 @@ jobs:
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
run: rustup update stable --no-self-update && rustup default stable
- name: Test
run: cargo test --lib --no-default-features --features tokio

run: cargo build --no-default-features --features alloc
no_std_and_future:
name: no_std & future
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install Rust
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
run: rustup update stable --no-self-update && rustup default stable
- name: Test
run: cargo build --no-default-features --features alloc,future
sync:
name: sync
strategy:
Expand All @@ -127,7 +142,7 @@ jobs:
name: cargo tarpaulin
runs-on: ubuntu-latest
needs:
- tokio
- no_std
- future
- sync
- build
Expand Down
26 changes: 9 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,38 @@ homepage = "https://github.com/al8n/wg"
repository = "https://github.com/al8n/wg.git"
documentation = "https://docs.rs/wg/"
readme = "README.md"
version = "0.8.3"
version = "0.9.0"
license = "MIT OR Apache-2.0"
keywords = ["waitgroup", "async", "sync", "notify", "wake"]
categories = ["asynchronous", "concurrency", "data-structures"]
categories = ["asynchronous", "concurrency", "data-structures", "no-std"]
edition = "2021"

[features]
default = ["std", "parking_lot", "triomphe"]
std = ["triomphe?/default", "event-listener?/default", "futures-core?/default", "tokio?/rt"]
alloc = ["event-listener"]
std = ["triomphe?/default", "event-listener?/default", "futures-core?/default"]
triomphe = ["dep:triomphe"]
parking_lot = ["dep:parking_lot"]

future = ["event-listener", "pin-project-lite", "agnostic-lite"]
tokio = ["dep:tokio", "futures-core", "pin-project-lite", "agnostic-lite/tokio"]
smol = ["agnostic-lite/smol", "future"]
async-std = ["agnostic-lite/async-std", "future"]
future = ["event-listener", "pin-project-lite"]

[dependencies]
parking_lot = { version = "0.12", optional = true }
triomphe = { version = "0.1", optional = true, default-features = false }
event-listener = { version = "5", optional = true, default-features = false }
pin-project-lite = { version = "0.2", optional = true }
event-listener = { version = "5", optional = true, default-features = false, features = ["portable-atomic"] }

tokio = { version = "1", optional = true, default-features = false, features = ["sync"] }
pin-project-lite = { version = "0.2", optional = true }
futures-core = { version = "0.3", default-features = false, optional = true }
agnostic-lite = { version = "0.3", optional = true }

[dev-dependencies]
agnostic-lite = { version = "0.3", features = ["smol", "async-std", "tokio", "time"] }
tokio = { version = "1", features = ["full"] }
async-std = { version = "1", features = ["attributes"] }
smol = "2"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[[test]]
name = "tokio"
path = "tests/tokio.rs"
required-features = ["tokio"]

[[test]]
name = "future"
path = "tests/future.rs"
Expand Down
87 changes: 30 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</div>
<div align="center">

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

[<img alt="github" src="https://img.shields.io/badge/GITHUB-al8n/wg-8da0cb?style=for-the-badge&logo=Github" height="22">][Github-url]
[<img alt="Build" src="https://img.shields.io/github/actions/workflow/status/al8n/wg/ci.yml?logo=Github-Actions&style=for-the-badge" height="22">][CI-url]
Expand All @@ -20,37 +20,42 @@ Golang like WaitGroup implementation for sync/async Rust.

By default, blocking version `WaitGroup` is enabled.

If you are using `tokio`, you need to enable `tokio` feature in your `Cargo.toml` and use `wg::tokio::AsyncWaitGroup`.

If you are using other async runtime, you need to
enbale `future` feature in your `Cargo.toml` and use `wg::future::AsyncWaitGroup`.
enbale `future` feature in your `Cargo.toml` and use `wg::AsyncWaitGroup`.

### Sync

```toml
[dependencies]
wg = "0.8"
```
## Installation

### `tokio`
- std

An async implementation for `tokio` runtime.
```toml
[dependencies]
wg = "0.9"
```

```toml
[dependencies]
wg = { version = "0.8", features = ["tokio"] }
```

### `future`
- `future`

A more generic async implementation.
```toml
[dependencies]
wg = { version = "0.9", features = ["future"] }
```

```toml
[dependencies]
wg = { version = "0.8", features = ["future"] }
```
- no_std

## Instruction
```toml
[dependencies]
wg = { version = "0.9", default_features = false, features = ["alloc"] }
```

- no_std & future

```toml
[dependencies]
wg = { version = "0.9", default_features = false, features = ["alloc", "future"] }
```

## Examples

### Sync

Expand Down Expand Up @@ -83,10 +88,10 @@ fn main() {
}
```

### `tokio`
### Async

```rust
use wg::tokio::AsyncWaitGroup;
use wg::AsyncWaitGroup;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use tokio::{spawn, time::{sleep, Duration}};
Expand Down Expand Up @@ -114,39 +119,6 @@ async fn main() {
}
```

### `async-io`

```rust
use wg::future::AsyncWaitGroup;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
use async_std::task::{spawn, block_on, sleep};

fn main() {
block_on(async {
let wg = AsyncWaitGroup::new();
let ctr = Arc::new(AtomicUsize::new(0));

for _ in 0..5 {
let ctrx = ctr.clone();
let t_wg = wg.add(1);
spawn(async move {
// mock some time consuming task
sleep(Duration::from_millis(50)).await;
ctrx.fetch_add(1, Ordering::Relaxed);

// mock task is finished
t_wg.done();
});
}

wg.wait().await;
assert_eq!(ctr.load(Ordering::Relaxed), 5);
});
}
```

## Acknowledgements

- Inspired by Golang sync.WaitGroup and [`crossbeam_utils::WaitGroup`].
Expand All @@ -158,6 +130,7 @@ Licensed under either of <a href="https://opensource.org/licenses/Apache-2.0">Ap
2.0</a> or <a href="https://opensource.org/licenses/MIT">MIT license</a> at your option.
</sup>


<sub>
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
Expand Down
5 changes: 3 additions & 2 deletions examples/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use tokio::{
spawn,
time::{sleep, Duration},
};
use wg::future::AsyncWaitGroup;
use wg::AsyncWaitGroup;

fn main() {
#[tokio::main]
async fn main() {
async_std::task::block_on(async {
let wg = AsyncWaitGroup::new();
let ctr = Arc::new(AtomicUsize::new(0));
Expand Down
29 changes: 0 additions & 29 deletions examples/tokio.rs

This file was deleted.

Loading

0 comments on commit 1c8bd57

Please sign in to comment.