Trait turbulence::runtime::Runtime
source · [−]pub trait Runtime: Clone + Send + Sync + Unpin {
type Instant: Copy + Send + Sync + Unpin;
type Sleep: Future<Output = ()> + Send;
fn spawn<F>(&self, future: F)
where
F: Future<Output = ()> + Send + 'static;
fn now(&self) -> Self::Instant;
fn elapsed(&self, instant: Self::Instant) -> Duration;
fn duration_between(
&self,
earlier: Self::Instant,
later: Self::Instant
) -> Duration;
fn sleep(&self, duration: Duration) -> Self::Sleep;
}
Expand description
Trait for async runtime functionality needed by turbulence
.
This is designed so that it can be implemented on multiple platforms with multiple runtimes,
including wasm32-unknown-unknown
, where std::time::Instant
is unavailable.
Associated Types
Required methods
This is similar to the futures::task::Spawn
trait, but it is generic in the spawned
future, which is better for backends like tokio.
Return the time elapsed since the given instant.
fn duration_between(
&self,
earlier: Self::Instant,
later: Self::Instant
) -> Duration
fn duration_between(
&self,
earlier: Self::Instant,
later: Self::Instant
) -> Duration
Similarly to std::time::Instant::duration_since
, may panic if later
comes before
earlier
.