taskwait

Crates.iotaskwait
lib.rstaskwait
version0.4.1
sourcesrc
created_at2021-03-13 10:47:01.906053
updated_at2021-03-19 18:18:43.711017
descriptionRuntime agnostic way to wait for a group of async tasks
homepagehttps://github.com/staticgc/taskwait
repositoryhttps://github.com/staticgc/taskwait
max_upload_size
id368250
size14,637
Sudeep Jathar (staticgc)

documentation

https://docs.rs/taskwait

README

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;
Commit count: 36

cargo fmt