use futures::future::FutureExt; use std::sync::mpsc; use std::task::Poll; use std::time::Duration; use std::{future::poll_fn, path::PathBuf}; use tempfile::NamedTempFile; use tokio::{
fs::OpenOptions,
runtime::{Builder, Runtime},
}; use tokio_util::task::TaskTracker;
let (_tmp_files, paths): (Vec<NamedTempFile>, Vec<PathBuf>) = create_tmp_files(NUM_FILES);
rt.block_on(asyncmove { let tracker = TaskTracker::new();
for i in 0..10_000 { let path = paths.get(i % NUM_FILES).unwrap().clone();
tracker.spawn(asyncmove { let _file = OpenOptions::new().read(true).open(path).await.unwrap();
});
}
tracker.close();
tracker.wait().await;
});
}
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel(); let handle = tokio::spawn(asyncmove {
poll_fn(|cx| { let opt = { letmut opt = tokio::fs::OpenOptions::new();
opt.read(true);
opt
};
let fut = opt.open(&path[0]);
// If io_uring is enabled (and not falling back to the thread pool), // the first poll should return Pending. let _pending = Box::pin(fut).poll_unpin(cx);
tx.send(()).unwrap();
Poll::<()>::Pending
})
.await;
});
// Wait for the first poll
rx.recv().await.unwrap();
handle.abort();
let res = handle.await.unwrap_err();
assert!(res.is_cancelled());
}
fn create_tmp_files(num_files: usize) -> (Vec<NamedTempFile>, Vec<PathBuf>) { letmut files = Vec::with_capacity(num_files);
for _ in 0..num_files { let tmp = NamedTempFile::new().unwrap(); let path = tmp.path().to_path_buf();
files.push((tmp, path));
}
files.into_iter().unzip()
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.