mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-16 00:00:12 +02:00
* Change a return value of reactor::poll to io::Result.
* Revert "Change a return value of reactor::poll to io::Result."
This reverts commit 281d8c32d4.
* Return a result from reactor::poll.
* Drop a reactor if any error occurs. Fix warnings in tests.
* Update a documentation for reactor::turn.
* Unwrap the last turn() call in tests.
44 lines
855 B
Rust
44 lines
855 B
Rust
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();
|
|
}
|