rust/tests/ui/async-await/async-closures/auxiliary/block-on.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
457 B
Rust
Raw Normal View History

2024-01-25 11:43:35 -06:00
// edition: 2021
#![feature(async_closure, noop_waker)]
2024-01-25 11:43:35 -06:00
use std::future::Future;
use std::pin::pin;
use std::task::*;
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
let mut fut = pin!(fut);
// Poll loop, just to test the future...
let ctx = &mut Context::from_waker(Waker::noop());
loop {
match unsafe { fut.as_mut().poll(ctx) } {
Poll::Pending => {}
Poll::Ready(t) => break t,
}
}
}