Skip to content

Commit 1c8bd57

Browse files
committed
Publish 0.9.0
1 parent 7e1dca4 commit 1c8bd57

File tree

12 files changed

+659
-898
lines changed

12 files changed

+659
-898
lines changed

.github/workflows/ci.yml

+21-6
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ jobs:
8787
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
8888
run: rustup update stable --no-self-update && rustup default stable
8989
- name: Test
90-
run: cargo test --lib --no-default-features --features future
90+
run: cargo test --lib --features future
9191

92-
tokio:
93-
name: tokio
92+
no_std:
93+
name: no_std
9494
strategy:
9595
matrix:
9696
os:
@@ -104,8 +104,23 @@ jobs:
104104
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
105105
run: rustup update stable --no-self-update && rustup default stable
106106
- name: Test
107-
run: cargo test --lib --no-default-features --features tokio
108-
107+
run: cargo build --no-default-features --features alloc
108+
no_std_and_future:
109+
name: no_std & future
110+
strategy:
111+
matrix:
112+
os:
113+
- ubuntu-latest
114+
- macos-latest
115+
- windows-latest
116+
runs-on: ${{ matrix.os }}
117+
steps:
118+
- uses: actions/checkout@v3
119+
- name: Install Rust
120+
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe.
121+
run: rustup update stable --no-self-update && rustup default stable
122+
- name: Test
123+
run: cargo build --no-default-features --features alloc,future
109124
sync:
110125
name: sync
111126
strategy:
@@ -127,7 +142,7 @@ jobs:
127142
name: cargo tarpaulin
128143
runs-on: ubuntu-latest
129144
needs:
130-
- tokio
145+
- no_std
131146
- future
132147
- sync
133148
- build

Cargo.toml

+9-17
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,38 @@ homepage = "https://github.com/al8n/wg"
66
repository = "https://github.com/al8n/wg.git"
77
documentation = "https://docs.rs/wg/"
88
readme = "README.md"
9-
version = "0.8.3"
9+
version = "0.9.0"
1010
license = "MIT OR Apache-2.0"
1111
keywords = ["waitgroup", "async", "sync", "notify", "wake"]
12-
categories = ["asynchronous", "concurrency", "data-structures"]
12+
categories = ["asynchronous", "concurrency", "data-structures", "no-std"]
1313
edition = "2021"
1414

1515
[features]
1616
default = ["std", "parking_lot", "triomphe"]
17-
std = ["triomphe?/default", "event-listener?/default", "futures-core?/default", "tokio?/rt"]
17+
alloc = ["event-listener"]
18+
std = ["triomphe?/default", "event-listener?/default", "futures-core?/default"]
1819
triomphe = ["dep:triomphe"]
1920
parking_lot = ["dep:parking_lot"]
20-
21-
future = ["event-listener", "pin-project-lite", "agnostic-lite"]
22-
tokio = ["dep:tokio", "futures-core", "pin-project-lite", "agnostic-lite/tokio"]
23-
smol = ["agnostic-lite/smol", "future"]
24-
async-std = ["agnostic-lite/async-std", "future"]
21+
future = ["event-listener", "pin-project-lite"]
2522

2623
[dependencies]
2724
parking_lot = { version = "0.12", optional = true }
2825
triomphe = { version = "0.1", optional = true, default-features = false }
29-
event-listener = { version = "5", optional = true, default-features = false }
30-
pin-project-lite = { version = "0.2", optional = true }
26+
event-listener = { version = "5", optional = true, default-features = false, features = ["portable-atomic"] }
3127

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

3631
[dev-dependencies]
32+
agnostic-lite = { version = "0.3", features = ["smol", "async-std", "tokio", "time"] }
3733
tokio = { version = "1", features = ["full"] }
3834
async-std = { version = "1", features = ["attributes"] }
35+
smol = "2"
3936

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

44-
[[test]]
45-
name = "tokio"
46-
path = "tests/tokio.rs"
47-
required-features = ["tokio"]
48-
4941
[[test]]
5042
name = "future"
5143
path = "tests/future.rs"

README.md

+30-57
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</div>
44
<div align="center">
55

6-
Golang like WaitGroup implementation for sync/async Rust.
6+
Golang like WaitGroup implementation for sync/async Rust, support `no_std` environment.
77

88
[<img alt="github" src="https://img.shields.io/badge/GITHUB-al8n/wg-8da0cb?style=for-the-badge&logo=Github" height="22">][Github-url]
99
[<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]
@@ -20,37 +20,42 @@ Golang like WaitGroup implementation for sync/async Rust.
2020

2121
By default, blocking version `WaitGroup` is enabled.
2222

23-
If you are using `tokio`, you need to enable `tokio` feature in your `Cargo.toml` and use `wg::tokio::AsyncWaitGroup`.
24-
2523
If you are using other async runtime, you need to
26-
enbale `future` feature in your `Cargo.toml` and use `wg::future::AsyncWaitGroup`.
24+
enbale `future` feature in your `Cargo.toml` and use `wg::AsyncWaitGroup`.
2725

28-
### Sync
2926

30-
```toml
31-
[dependencies]
32-
wg = "0.8"
33-
```
27+
## Installation
3428

35-
### `tokio`
29+
- std
3630

37-
An async implementation for `tokio` runtime.
31+
```toml
32+
[dependencies]
33+
wg = "0.9"
34+
```
3835

39-
```toml
40-
[dependencies]
41-
wg = { version = "0.8", features = ["tokio"] }
42-
```
4336

44-
### `future`
37+
- `future`
4538

46-
A more generic async implementation.
39+
```toml
40+
[dependencies]
41+
wg = { version = "0.9", features = ["future"] }
42+
```
4743

48-
```toml
49-
[dependencies]
50-
wg = { version = "0.8", features = ["future"] }
51-
```
44+
- no_std
5245

53-
## Instruction
46+
```toml
47+
[dependencies]
48+
wg = { version = "0.9", default_features = false, features = ["alloc"] }
49+
```
50+
51+
- no_std & future
52+
53+
```toml
54+
[dependencies]
55+
wg = { version = "0.9", default_features = false, features = ["alloc", "future"] }
56+
```
57+
58+
## Examples
5459

5560
### Sync
5661

@@ -83,10 +88,10 @@ fn main() {
8388
}
8489
```
8590

86-
### `tokio`
91+
### Async
8792

8893
```rust
89-
use wg::tokio::AsyncWaitGroup;
94+
use wg::AsyncWaitGroup;
9095
use std::sync::Arc;
9196
use std::sync::atomic::{AtomicUsize, Ordering};
9297
use tokio::{spawn, time::{sleep, Duration}};
@@ -114,39 +119,6 @@ async fn main() {
114119
}
115120
```
116121

117-
### `async-io`
118-
119-
```rust
120-
use wg::future::AsyncWaitGroup;
121-
use std::sync::Arc;
122-
use std::sync::atomic::{AtomicUsize, Ordering};
123-
use std::time::Duration;
124-
use async_std::task::{spawn, block_on, sleep};
125-
126-
fn main() {
127-
block_on(async {
128-
let wg = AsyncWaitGroup::new();
129-
let ctr = Arc::new(AtomicUsize::new(0));
130-
131-
for _ in 0..5 {
132-
let ctrx = ctr.clone();
133-
let t_wg = wg.add(1);
134-
spawn(async move {
135-
// mock some time consuming task
136-
sleep(Duration::from_millis(50)).await;
137-
ctrx.fetch_add(1, Ordering::Relaxed);
138-
139-
// mock task is finished
140-
t_wg.done();
141-
});
142-
}
143-
144-
wg.wait().await;
145-
assert_eq!(ctr.load(Ordering::Relaxed), 5);
146-
});
147-
}
148-
```
149-
150122
## Acknowledgements
151123

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

133+
161134
<sub>
162135
Unless you explicitly state otherwise, any contribution intentionally submitted
163136
for inclusion in this project by you, as defined in the Apache-2.0 license,

examples/future.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use tokio::{
44
spawn,
55
time::{sleep, Duration},
66
};
7-
use wg::future::AsyncWaitGroup;
7+
use wg::AsyncWaitGroup;
88

9-
fn main() {
9+
#[tokio::main]
10+
async fn main() {
1011
async_std::task::block_on(async {
1112
let wg = AsyncWaitGroup::new();
1213
let ctr = Arc::new(AtomicUsize::new(0));

examples/tokio.rs

-29
This file was deleted.

0 commit comments

Comments
 (0)