mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00

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.
38 lines
792 B
Rust
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());
|
|
}
|