2024-01-25 11:43:35 -06:00
|
|
|
// edition: 2021
|
|
|
|
|
2024-02-06 11:41:48 -06:00
|
|
|
#![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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|