mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-20 00:00:08 +02:00
Make Handle::wakeup private (#117)
The `Handle` type is intended to be used by end users of Tokio. The wakeup functionlity is needed by executor implementations. It doesn't make sense to put executor specific functionality on a type that is intended for end users.
This commit is contained in:
+1
-1
@@ -350,7 +350,7 @@ impl Handle {
|
||||
/// after this method has been called. If the reactor is not currently
|
||||
/// blocked in `turn`, then the next call to `turn` will not block and
|
||||
/// return immediately.
|
||||
pub fn wakeup(&self) {
|
||||
fn wakeup(&self) {
|
||||
if let Some(inner) = self.inner() {
|
||||
inner.wakeup.set_readiness(mio::Ready::readable()).unwrap();
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
extern crate tokio;
|
||||
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::sync::mpsc;
|
||||
|
||||
use tokio::reactor::Reactor;
|
||||
|
||||
#[test]
|
||||
fn works() {
|
||||
let mut r = Reactor::new().unwrap();
|
||||
r.handle().wakeup();
|
||||
r.turn(None).unwrap();
|
||||
|
||||
let now = Instant::now();
|
||||
let mut n = 0;
|
||||
while now.elapsed() < Duration::from_millis(10) {
|
||||
n += 1;
|
||||
r.turn(Some(Duration::from_millis(10))).unwrap();
|
||||
}
|
||||
assert!(n < 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wakes() {
|
||||
const N: usize = 1_000;
|
||||
|
||||
let mut r = Reactor::new().unwrap();
|
||||
let handle = r.handle();
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let t = thread::spawn(move || {
|
||||
for _ in 0..N {
|
||||
rx.recv().unwrap();
|
||||
handle.wakeup();
|
||||
}
|
||||
});
|
||||
|
||||
for _ in 0..N {
|
||||
tx.send(()).unwrap();
|
||||
r.turn(None).unwrap();
|
||||
}
|
||||
t.join().unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user