#wait #async-task #tasks #wait-group #async #async-await #await

taskwait

Runtime agnostic way to wait for a group of async tasks

7 unstable releases (3 breaking)

0.4.1 Mar 19, 2021
0.4.0 Mar 17, 2021
0.3.1 Mar 14, 2021
0.2.1 Mar 13, 2021
0.1.0 Mar 13, 2021

#2016 in Asynchronous

Download history 18/week @ 2024-07-16 19/week @ 2024-07-23 5/week @ 2024-07-30 1/week @ 2024-09-03 12/week @ 2024-09-10 4/week @ 2024-09-24 4/week @ 2024-10-01

77 downloads per month

MIT license

14KB
227 lines

Crates.io docs.rs Build

taskwait

Runtime agnostic way of waiting for async tasks.

Features

  • Done: Support for golang's WaitGroup.Add & WaitGroup.Done
  • Done: Support for RAII based done()ing the task i.e. calling done() on drop.
  • Done: Mixing of both add, done and RAII semantics.
  • Done: Reuse the same taskgroup for multiple checkpoints.

Example

Using add & done

use taskwait::TaskGroup;
 
let tg = TaskGroup::();
for _ in 0..10 {
    tg.add();
    let tg_c = tg.clone();
    tokio::spawn(async move{
        ...
        tg_c.done();
    })
}
tg.wait().await;

Using add & add_work

use taskwait::TaskGroup;
 
let tg = TaskGroup::();
for _ in 0..10 {
    let work = tg.add_work(1); // Increment counter
    tokio::spawn(async move{
        let _work = work; // done() will be called when this is dropped
        ...
    })
}
tg.wait().await;

Dependencies

~530–710KB
~14K SLoC