turboflight

Crates.ioturboflight
lib.rsturboflight
version2.3.1
created_at2025-10-17 01:13:10.259246+00
updated_at2025-11-14 18:02:05.787764+00
descriptionA simple, concurrent single-flight implementation.
homepage
repositoryhttps://github.com/nekidev/turboflight
max_upload_size
id1886981
size16,804
Rafael Bradley (Nekidev)

documentation

README

turboflight

A simple single-flight implementation for heavy concurrency.

Simple Usage

use turboflight::SingleFlight;
use tokio::time::{self, Duration};

#[tokio::main]
async fn main() {
    let group = SingleFlight::new();

    let mut tasks = vec![];

    for _ in 0..10 {
        let group = group.clone();  // The inner state of the group is an Arc so it's cheaply clonable.
        tasks.push(tokio::spawn(async move {
            group.work(1, async {
                println!("Doing work...");
                time::sleep(Duration::from_secs(1)).await;
                println!("Work done!");

                100
            }).await
        }));
        println!("Task spawned");
    }

    let results = futures::future::join_all(tasks).await;

    assert!(results.into_iter().all(|res| res.unwrap() == 100));
}

Documentation

For the full documentation, check docs.rs/turboflight.

Commit count: 0

cargo fmt