1#![no_std]
4
5use core::{
6 pin::pin,
7 task::{Context, Poll, Waker},
8};
9
10pub fn block_on<T>(future: impl Future<Output = T>) -> T {
14 let Poll::Ready(result) = pin!(future).poll(&mut Context::from_waker(Waker::noop())) else {
15 unreachable!()
16 };
17
18 result
19}
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24 use core::future::{pending, ready};
25
26 #[test]
27 fn resolve_ready_future() {
28 assert_eq!(block_on(async { 42 }), 42);
29 assert_eq!(block_on(ready(42)), 42);
30 }
31
32 #[test]
33 #[should_panic]
34 fn panic_on_pending_future() {
35 assert_eq!(block_on(pending::<usize>()), 42);
36 }
37}