| Crates.io | turboflight |
| lib.rs | turboflight |
| version | 2.3.1 |
| created_at | 2025-10-17 01:13:10.259246+00 |
| updated_at | 2025-11-14 18:02:05.787764+00 |
| description | A simple, concurrent single-flight implementation. |
| homepage | |
| repository | https://github.com/nekidev/turboflight |
| max_upload_size | |
| id | 1886981 |
| size | 16,804 |
A simple single-flight implementation for heavy concurrency.
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));
}
For the full documentation, check docs.rs/turboflight.