Skip to content

Commit 02eda72

Browse files
authored
Merge pull request #161 from zh-jq-b/fastrand
use fastrand instead of nanorand
2 parents d185c56 + 6af34d0 commit 02eda72

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ rustdoc-args = ["--cfg", "docsrs"]
2424
spin = []
2525
select = []
2626
async = ["futures-sink", "futures-core"]
27-
eventual-fairness = ["select", "nanorand"]
27+
eventual-fairness = ["select", "fastrand"]
2828
default = ["async", "select", "eventual-fairness"]
2929

3030
[dependencies]
3131
spin1 = { package = "spin", version = "0.9.8", features = ["mutex"] }
3232
futures-sink = { version = "0.3", default_features = false, optional = true }
3333
futures-core = { version = "0.3", default_features = false, optional = true }
34-
nanorand = { version = "0.7", features = ["getrandom"], optional = true }
34+
fastrand = { version = "2.3", features = ["std", "js"], optional = true }
3535

3636
[dev-dependencies]
3737
#flume-test = { path = "../flume-test" }

src/select.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ use crate::*;
44
use spin1::Mutex as Spinlock;
55
use std::{any::Any, marker::PhantomData};
66

7-
#[cfg(feature = "eventual-fairness")]
8-
use nanorand::Rng;
9-
107
// A unique token corresponding to an event in a selector
118
type Token = usize;
129

@@ -81,7 +78,7 @@ pub struct Selector<'a, T: 'a> {
8178
next_poll: usize,
8279
signalled: Arc<Spinlock<VecDeque<Token>>>,
8380
#[cfg(feature = "eventual-fairness")]
84-
rng: nanorand::WyRand,
81+
rng: fastrand::Rng,
8582
phantom: PhantomData<*const ()>,
8683
}
8784

@@ -106,7 +103,7 @@ impl<'a, T> Selector<'a, T> {
106103
signalled: Arc::default(),
107104
phantom: PhantomData::default(),
108105
#[cfg(feature = "eventual-fairness")]
109-
rng: nanorand::WyRand::new(),
106+
rng: fastrand::Rng::new(),
110107
}
111108
}
112109

@@ -320,7 +317,7 @@ impl<'a, T> Selector<'a, T> {
320317
fn wait_inner(mut self, deadline: Option<Instant>) -> Option<T> {
321318
#[cfg(feature = "eventual-fairness")]
322319
{
323-
self.next_poll = self.rng.generate_range(0..self.selections.len());
320+
self.next_poll = self.rng.usize(0..self.selections.len());
324321
}
325322

326323
let res = 'outer: loop {

0 commit comments

Comments
 (0)