tokio/tokio-sync/tests/atomic_waker.rs
Carl Lerche 06c473e628
Update Tokio to use std::future. (#1120)
A first pass at updating Tokio to use `std::future`.

Implementations of `Future` from the futures crate are updated to implement
`Future` from std. Implementations of `Stream` are moved to a feature flag.

This commits disables a number of crates that have not yet been updated.
2019-06-24 12:34:30 -07:00

38 lines
792 B
Rust

#![deny(warnings, rust_2018_idioms)]
use std::task::Waker;
use tokio_sync::task::AtomicWaker;
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());
}