Skip to content

Commit

Permalink
bumpup version
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Oct 6, 2024
1 parent 57a06d4 commit ddcb97b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 68 deletions.
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://github.com/al8n/wg"
repository = "https://github.com/al8n/wg.git"
documentation = "https://docs.rs/wg/"
readme = "README.md"
version = "0.9.1"
version = "0.9.2"
license = "MIT OR Apache-2.0"
keywords = ["waitgroup", "async", "sync", "notify", "wake"]
categories = ["asynchronous", "concurrency", "data-structures", "no-std"]
Expand All @@ -26,12 +26,12 @@ triomphe = { version = "0.1", optional = true, default-features = false }
event-listener = { version = "5", optional = true, default-features = false, features = ["portable-atomic"] }

pin-project-lite = { version = "0.2", optional = true }
futures-core = { version = "0.3", default-features = false, optional = true }
futures-core = { version = "^0.3.31", default-features = false, optional = true }

crossbeam-utils = { version = "0.8", optional = true, default-features = false }

[dev-dependencies]
agnostic-lite = { version = "0.3", features = ["smol", "async-std", "tokio", "time"] }
agnostic-lite = { version = "^0.3.16", features = ["smol", "async-std", "tokio", "time"] }
tokio = { version = "1", features = ["full"] }
async-std = { version = "1", features = ["attributes"] }
smol = "2"
Expand All @@ -43,9 +43,14 @@ rustdoc-args = ["--cfg", "docsrs"]
[[test]]
name = "future"
path = "tests/future.rs"
required-features = ["future"]
required-features = ["tokio"]

[[test]]
name = "sync"
path = "tests/sync.rs"

[[example]]
name = "future"
path = "examples/future.rs"
required-features = ["tokio"]

62 changes: 1 addition & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,67 +57,7 @@ enbale `future` feature in your `Cargo.toml` and use `wg::AsyncWaitGroup`.

## Examples

### Sync

```rust
use wg::WaitGroup;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;
use std::thread::{spawn, sleep};

fn main() {
let wg = WaitGroup::new();
let ctr = Arc::new(AtomicUsize::new(0));

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

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

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

### Async

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

#[tokio::main]
async fn main() {
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);
}
```
Please see [examples](./examples) for details.

## Acknowledgements

Expand Down
3 changes: 2 additions & 1 deletion src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct AsyncInner {
}

/// An AsyncWaitGroup waits for a collection of threads to finish.
///
/// The main thread calls [`add`] to set the number of
/// thread to wait for. Then each of the tasks
/// runs and calls Done when finished. At the same time,
Expand Down Expand Up @@ -280,7 +281,7 @@ pin_project_lite::pin_project! {
}
}

impl<'a> core::future::Future for WaitGroupFuture<'a> {
impl core::future::Future for WaitGroupFuture<'_> {
type Output = ();

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Expand Down
11 changes: 9 additions & 2 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ trait Mu {

#[cfg(feature = "parking_lot")]
impl<T: ?Sized> Mu for parking_lot::Mutex<T> {
type Guard<'a> = parking_lot::MutexGuard<'a, T> where Self: 'a;
type Guard<'a>
= parking_lot::MutexGuard<'a, T>
where
Self: 'a;

fn lock_me(&self) -> Self::Guard<'_> {
self.lock()
Expand All @@ -16,7 +19,10 @@ impl<T: ?Sized> Mu for parking_lot::Mutex<T> {

#[cfg(not(feature = "parking_lot"))]
impl<T: ?Sized> Mu for std::sync::Mutex<T> {
type Guard<'a> = std::sync::MutexGuard<'a, T> where Self: 'a;
type Guard<'a>
= std::sync::MutexGuard<'a, T>
where
Self: 'a;

fn lock_me(&self) -> Self::Guard<'_> {
self.lock().unwrap()
Expand All @@ -38,6 +44,7 @@ struct Inner {
}

/// A WaitGroup waits for a collection of threads to finish.
///
/// The main thread calls [`add`] to set the number of
/// thread to wait for. Then each of the goroutines
/// runs and calls Done when finished. At the same time,
Expand Down

0 comments on commit ddcb97b

Please sign in to comment.