waitout 0.1.0

Awaits the completion of multiple async tasks
Documentation

waitout

Build Status

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

api docs

Find them here.

usage

It's sometimes useful 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 maintain the current state of their completion. Some libraries have interfaces like CountDownLatches and WaitGroups to help solve this problem. Absent of a similar solution in rust, the motivation for waitout was born.

Waitout is a simple wrapper around of few 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