Skip to content

Commit

Permalink
Fix wait(): sleep to spin_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
just-do-halee committed Dec 5, 2022
1 parent a254219 commit fc1a295
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wag"
authors = ["just-do-halee <just.do.halee@gmail.com>"]
version = "0.2.0"
version = "0.3.0"
edition = "2021"
categories = ["asynchronous", "concurrency", "rust-patterns"]
keywords = ["sync", "async", "wait", "waitgroup", "wake"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Go like sync.WaitGroup implementation in Rust. (sync/async)
| [Examples](./tests/) | [Docs](https://docs.rs/wag) | [Latest Note](./CHANGELOG.md) |

```toml
wag = "0.2.0"
wag = "0.3.0"
```

## **`How to use,`**
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::hint;
use std::sync::Arc;

pub struct WaitChild(Arc<()>);
Expand All @@ -22,10 +23,8 @@ impl WaitGroup {
(0..N).map(|_| self.add())
}
pub fn wait(self) {
use std::{thread::sleep, time::Duration};

while Arc::strong_count(&self.0) > 1 {
sleep(Duration::from_millis(1));
hint::spin_loop();
}
}
pub async fn async_wait(self) {
Expand Down

0 comments on commit fc1a295

Please sign in to comment.