2 releases

Uses old Rust 2015

0.1.1 Nov 29, 2015
0.1.0 Nov 27, 2015

#14 in #wait-group

MIT license

4KB

waitout

Build Status

Waitout provides a simple interface for tracking and awaiting the completion of multiple asynchounous tasks.

api docs

Find them here.

install

Add the following to you're Cargo.toml file

[dependencies]
waitout = "0.1"

usage

It's sometimes useful to fan out independant tasks asynchronously for efficient completion of an aggregate task. Asynchronous tasks may sometimes be staged in various scopes making it difficult to monitor the current state of their completion. Some languages have std library interfaces like CountDownLatches and WaitGroups to help solve this problem. Absent of a similar interface in rust, the motivation for waitout was born.

Waitout is a simple wrapper around of few rust synchronisation primitives that make staged task completion more straight forward. The idea is simple, keep reference create a shared counter that increments for every task you wish to wait on. When a task completes decrement that counter. When the counter reaches 0, the current thread may proceed.

extern crate waitout;

use std::sync::Arc;
use std::thread;
use waitout::WaitGroup;

fn main() {
    let wg = Arc::new(
        WaitGroup::new(0)
    );
    for _ in 0..100 {
        wg.add(1);
        let wg2 = wg.clone();
        thread::spawn(move|| {
            thread::sleep_ms(2000);
            wg2.done();
        });
    }
    wg.wait();
    println!("all set")
}

Doug Tangren (softprops) 2015

No runtime deps