2019-08-10 00:07:57 +09:00
|
|
|
#![warn(rust_2018_idioms)]
|
2019-06-24 12:34:30 -07:00
|
|
|
|
|
|
|
|
use std::task::Waker;
|
2019-08-06 13:54:56 -07:00
|
|
|
use tokio_sync::AtomicWaker;
|
2019-06-24 12:34:30 -07:00
|
|
|
use tokio_test::task::MockTask;
|
|
|
|
|
|
|
|
|
|
trait AssertSend: Send {}
|
|
|
|
|
trait AssertSync: Send {}
|
|
|
|
|
|
|
|
|
|
impl AssertSend for AtomicWaker {}
|
|
|
|
|
impl AssertSync for AtomicWaker {}
|
|
|
|
|
|
|
|
|
|
impl AssertSend for Waker {}
|
|
|
|
|
impl AssertSync for Waker {}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn basic_usage() {
|
|
|
|
|
let waker = AtomicWaker::new();
|
|
|
|
|
let mut task = MockTask::new();
|
|
|
|
|
|
|
|
|
|
task.enter(|cx| waker.register_by_ref(cx.waker()));
|
|
|
|
|
waker.wake();
|
|
|
|
|
|
|
|
|
|
assert!(task.is_woken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn wake_without_register() {
|
|
|
|
|
let waker = AtomicWaker::new();
|
|
|
|
|
waker.wake();
|
|
|
|
|
|
|
|
|
|
// Registering should not result in a notification
|
|
|
|
|
let mut task = MockTask::new();
|
|
|
|
|
task.enter(|cx| waker.register_by_ref(cx.waker()));
|
|
|
|
|
|
|
|
|
|
assert!(!task.is_woken());
|
|
|
|
|
}
|