use std::future::Future;
use std::sync::{Arc, Mutex};
pub fn block_on<Fut, T>(make_future: impl FnOnce() -> Fut + Send + 'static) -> T
where
Fut: Future<Output = T> + 'static,
T: Send + 'static,
{
std::thread::spawn(move || {
let slot: Arc<Mutex<Option<T>>> = Arc::new(Mutex::new(None));
let writer = Arc::clone(&slot);
runite::spawn(async move {
let value = make_future().await;
*writer.lock().expect("result slot poisoned") = Some(value);
});
runite::run();
slot.lock()
.expect("result slot poisoned")
.take()
.expect("runtime drained without resolving the future")
})
.join()
.expect("runtime thread panicked")
}