curfew 0.0.5

A deadline-aware fork-join model where multiple tasks run in parallel, but only those that finish before a specified absolute clock time are joined and their results collected.
Documentation
use curfew::{DeadlineJoiner, TaskOutcome};
use std::thread;
use std::time::{Duration, Instant};

fn main() {
    let deadline = Instant::now() + Duration::from_millis(200);
    let mut joiner = DeadlineJoiner::new(deadline);

    for job in 0..4 {
        joiner.spawn(move || {
            thread::sleep(Duration::from_millis(40 * job));
            format!("job {job}")
        });
    }

    let summary = joiner.join_ready();
    println!("{} tasks finished on time", summary.completed_count());
    println!("{} tasks missed the deadline", summary.timed_out_count());

    for result in summary.completed {
        let task_id = result.task_id;
        let duration = result.duration();
        match result.outcome {
            TaskOutcome::Completed(value) => {
                println!("{value} completed in {:?}", duration)
            }
            TaskOutcome::Panicked(info) => {
                println!("task {task_id} panicked: {info}")
            }
        }
    }

    if !summary.timed_out.is_empty() {
        println!(
            "Still running: {:?}",
            summary
                .timed_out
                .iter()
                .map(|task| task.task_id)
                .collect::<Vec<_>>()
        );
    }
}