use super::{DroppableFuture, Runtime};
use futures_lite::{FutureExt, Stream};
use std::{future::Future, time::Duration};
pub trait RuntimeTrait: Into<Runtime> + Clone + Send + Sync + 'static {
fn spawn<Fut>(
&self,
fut: Fut,
) -> DroppableFuture<impl Future<Output = Option<Fut::Output>> + Send + 'static>
where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static;
fn delay(&self, duration: Duration) -> impl Future<Output = ()> + Send;
fn interval(&self, period: Duration) -> impl Stream<Item = ()> + Send + 'static;
fn block_on<Fut>(&self, fut: Fut) -> Fut::Output
where
Fut: Future;
fn timeout<'runtime, 'fut, Fut>(
&'runtime self,
duration: Duration,
fut: Fut,
) -> impl Future<Output = Option<Fut::Output>> + Send + 'fut
where
Fut: Future + Send + 'fut,
Fut::Output: Send + 'static,
'runtime: 'fut,
{
async move { Some(fut.await) }.race(async move {
self.delay(duration).await;
None
})
}
fn hook_signals(
&self,
signals: impl IntoIterator<Item = i32>,
) -> impl Stream<Item = i32> + Send + 'static {
let _ = signals;
futures_lite::stream::empty()
}
}