mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
e96b4e479a
By moving `block_on` to an auxiliary crate, we avoid having to keep a separate copy of it in every async test. (This also incorporates some small tweaks to the headers in `await_ready.rs`.)
20 lines
516 B
Rust
20 lines
516 B
Rust
#![feature(coverage_attribute, noop_waker)]
|
|
//@ edition: 2021
|
|
|
|
use core::future::Future;
|
|
use core::pin::pin;
|
|
use core::task::{Context, Poll, Waker};
|
|
|
|
/// Dummy "executor" that just repeatedly polls a future until it's ready.
|
|
#[coverage(off)]
|
|
pub fn block_on<F: Future>(mut future: F) -> F::Output {
|
|
let mut future = pin!(future);
|
|
let mut context = Context::from_waker(Waker::noop());
|
|
|
|
loop {
|
|
if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
|
|
break val;
|
|
}
|
|
}
|
|
}
|