forked from lavina/lavina
17 lines
442 B
Rust
17 lines
442 B
Rust
use std::future::Future;
|
|
use std::task::{Context, Poll};
|
|
|
|
use futures_util::task::noop_waker_ref;
|
|
use tokio::pin;
|
|
|
|
pub fn sync_future<T>(future: impl Future<Output = T>) -> anyhow::Result<T> {
|
|
let waker = noop_waker_ref();
|
|
let mut context = Context::from_waker(waker);
|
|
pin!(future);
|
|
if let Poll::Ready(a) = future.poll(&mut context) {
|
|
Ok(a)
|
|
} else {
|
|
Err(anyhow::Error::msg("Future has suspended"))
|
|
}
|
|
}
|