about summary refs log tree commit diff
path: root/tests/ui/async-await/async-fn/auxiliary/block-on.rs
blob: 4ec45ddf333596551b0dc54e81e46bfb17249ee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//@ edition: 2021

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,
        }
    }
}