File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed
Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ Works seamlessly with Tokio:
8181``` rust
8282use std :: {iter :: repeat_n, time :: Duration };
8383
84- use compact_waitgroup :: {WaitGroup , WithWorkerHandle };
84+ use compact_waitgroup :: {GroupTokenExt , WaitGroup };
8585use tokio :: time :: sleep;
8686
8787#[tokio:: main]
@@ -101,8 +101,17 @@ async fn main() {
101101 }
102102 });
103103
104- // Wait for the task to complete
105- wg . await ;
104+ tokio :: pin! (wg );
105+ loop {
106+ tokio :: select! {
107+ _ = sleep (Duration :: from_millis (200 )) => {
108+ println! (" Running..." );
109+ }
110+ _ = & mut wg => {
111+ break ;
112+ }
113+ };
114+ }
106115 println! (" All done!" );
107116}
108117```
Original file line number Diff line number Diff line change 4545//! # });
4646//! ```
4747//!
48+ //! ## With `async` Runtime
49+ //!
50+ //! ```rust
51+ //! # use core::{iter::repeat_n, mem::drop as spawn, time::Duration};
52+ //! # use compact_waitgroup::{GroupTokenExt, WaitGroup};
53+ //! # let sleep = |_| async {};
54+ //! # futures_executor::block_on(async {
55+ //! let (wg, factory) = WaitGroup::new();
56+ //! for (i, token) in repeat_n(factory.into_token(), 8).enumerate() {
57+ //! let task = async move {
58+ //! println!("Task {i} started");
59+ //! // Long-running task...
60+ //! sleep(Duration::from_secs(1)).await;
61+ //! println!("Task {i} finished");
62+ //! }
63+ //! .release_on_ready(token);
64+ //! spawn(task);
65+ //! }
66+ //! // Wait for all tasks to complete
67+ //! wg.await;
68+ //! # });
69+ //! ```
70+ //!
4871//! # Memory Layout
4972//!
5073//! This crate is designed to be extremely lightweight. The memory footprint
You can’t perform that action at this time.
0 commit comments