lavina/src/util/testkit.rs

17 lines
417 B
Rust
Raw Normal View History

2023-02-12 12:15:31 +00:00
use std::task::{Context, Poll};
use futures_util::task::noop_waker_ref;
use crate::prelude::*;
pub fn sync_future<T>(future: impl Future<Output = T>) -> 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"))
}
}