forked from lavina/lavina
1
0
Fork 0
lavina/crates/proto-irc/src/testkit.rs

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"))
}
}