From 1a9e08ce73f2c356103bfaf14cafd6fde376565b Mon Sep 17 00:00:00 2001 From: John Nunley Date: Fri, 9 Jun 2023 17:53:03 -0700 Subject: [PATCH] Use fastrand v2.0.0 (#45) --- Cargo.toml | 2 +- src/lib.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5a6f068..5792614 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ exclude = ["/.*"] async-lock = "2.6" async-task = "4.0.0" concurrent-queue = "2.0.0" -fastrand = "1.3.4" +fastrand = "2.0.0" futures-lite = "1.11.0" slab = "0.4.4" diff --git a/src/lib.rs b/src/lib.rs index 5a1d203..d8e59ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -227,12 +227,13 @@ impl<'a> Executor<'a> { /// ``` pub async fn run(&self, future: impl Future) -> T { let runner = Runner::new(self.state()); + let mut rng = fastrand::Rng::new(); // A future that runs tasks forever. let run_forever = async { loop { for _ in 0..200 { - let runnable = runner.runnable().await; + let runnable = runner.runnable(&mut rng).await; runnable.run(); } future::yield_now().await; @@ -748,7 +749,7 @@ impl Runner<'_> { } /// Waits for the next runnable task to run. - async fn runnable(&self) -> Runnable { + async fn runnable(&self, rng: &mut fastrand::Rng) -> Runnable { let runnable = self .ticker .runnable_with(|| { @@ -768,7 +769,7 @@ impl Runner<'_> { // Pick a random starting point in the iterator list and rotate the list. let n = local_queues.len(); - let start = fastrand::usize(..n); + let start = rng.usize(..n); let iter = local_queues .iter() .chain(local_queues.iter())