//! Platform-aware future utilities.12crate::cfg::switch! {3#[cfg(feature = "async-io")] => {4pub use async_io::block_on;5}6#[cfg(feature = "futures-lite")] => {7pub use futures_lite::future::block_on;8}9_ => {10/// Blocks on the supplied `future`.11/// This implementation will busy-wait until it is completed.12/// Consider enabling the `async-io` or `futures-lite` features.13pub fn block_on<T>(future: impl Future<Output = T>) -> T {14use core::task::{Poll, Context};1516// Pin the future on the stack.17let mut future = core::pin::pin!(future);1819// We don't care about the waker as we're just going to poll as fast as possible.20let cx = &mut Context::from_waker(core::task::Waker::noop());2122// Keep polling until the future is ready.23loop {24match future.as_mut().poll(cx) {25Poll::Ready(output) => return output,26Poll::Pending => core::hint::spin_loop(),27}28}29}30}31}323334