[][src]Trait turbulence::runtime::Runtime

pub trait Runtime: Clone + Send + Sync {
    type Instant: Copy + Send + Sync;
    type Delay: Future<Output = ()> + Unpin + Send;
    type Interval: Stream<Item = Self::Instant> + Unpin + 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 delay(&self, duration: Duration) -> Self::Delay;
fn interval(&self, duration: Duration) -> Self::Interval; }

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

type Instant: Copy + Send + Sync

type Delay: Future<Output = ()> + Unpin + Send

type Interval: Stream<Item = Self::Instant> + Unpin + Send

Loading content...

Required methods

fn spawn<F>(&self, future: F) where
    F: Future<Output = ()> + Send + 'static, 

This is similar to the futures::task::Spawn trait, but it is generic in the spawned future, which is better for backends like tokio.

fn now(&self) -> Self::Instant

Return the current instant.

fn elapsed(&self, instant: Self::Instant) -> Duration

Return the time elapsed since the given instant.

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.

fn delay(&self, duration: Duration) -> Self::Delay

Create a future which resolves after the given time has passed.

fn interval(&self, duration: Duration) -> Self::Interval

Create a stream which produces values continuously at the given interval.

Loading content...

Implementations on Foreign Types

impl<'a, R: Runtime> Runtime for &'a R[src]

type Instant = R::Instant

type Delay = R::Delay

type Interval = R::Interval

Loading content...

Implementors

Loading content...