use std::time::Duration;

use tokio::task::yield_now;
use tokio::time;
use tokio::time::Instant;
use waitgroup::WaitGroup;

#[tokio::main]
async fn main() {
    let wg = WaitGroup::new();
    for i in 80..100 {
        let w = wg.worker();
        tokio::spawn(async move {
            println!("Start work #{}", i);
            time::sleep(Duration::from_millis(i * 100)).await;
            println!("Finish work #{}", i);
            drop(w);
        });
        yield_now().await;
    }

    let instant = Instant::now();
    println!("Start waiting...");
    wg.wait().await;
    println!("Finish wait, elapsed: {}ms", instant.elapsed().as_millis());
}
