speedracer

Crates.iospeedracer
lib.rsspeedracer
version0.1.2
sourcesrc
created_at2022-11-17 11:03:43.253089
updated_at2022-12-11 08:21:38.189626
descriptionA crate for racing futures and ranking the results
homepagehttps://github.com/SeedyROM/speedracer
repositoryhttps://github.com/SeedyROM/speedracer
max_upload_size
id717119
size9,691
Zack Kollar (SeedyROM)

documentation

https://docs.rs/speedracer

README

A crate for racing Futures and getting ranked results back.

Example

use tokio::time::sleep;
use std::time::Duration;

use speedracer::RaceTrack;

let mut race_track = RaceTrack::disqualify_after(Duration::from_millis(500));

race_track.add_racer("Racer #1", async move {
    println!("Racer #1 is starting");
    sleep(std::time::Duration::from_millis(100)).await;
    println!("Racer #1 is ending");

    Ok(())
});
race_track.add_racer("Racer #2", async move {
    println!("Racer #2 is starting");
    sleep(std::time::Duration::from_secs(200)).await;
    println!("Racer #2 is ending");

    Ok(())
});
race_track.add_racer("Racer #3", async move {
    println!("Racer #3 is starting");
    sleep(std::time::Duration::from_secs(700)).await;
    println!("Racer #3 is ending");

    Ok(())
});

race_track.run().await;
let rankings = race_track.rankings();

println!("Rankings: {:?}", rankings);

assert_eq!(rankings[0].name, "Racer #1");
assert_eq!(rankings[1].name, "Racer #2");
assert_eq!(rankings[2].name, "Racer #3");
assert_eq!(rankings[2].disqualified, true);

Commit count: 7

cargo fmt