pub trait Runtime: Clone + Send + Sync + 'static {
    type Interval: Stream + Send;
    type Delay: Future + Send + Unpin;

    // Required methods
    fn interval(&self, duration: Duration) -> Self::Interval;
    fn spawn(
        &self,
        future: Pin<Box<dyn Future<Output = ()> + Send + 'static, Global>>
    );
    fn delay(&self, duration: Duration) -> Self::Delay;
}
Expand description

A runtime is an abstraction of an async runtime like Tokio or async-std. It allows OpenTelemetry to work with any current and hopefully future runtime implementation.

Required Associated Types§

source

type Interval: Stream + Send

A future stream, which returns items in a previously specified interval. The item type is not important.

source

type Delay: Future + Send + Unpin

A future, which resolves after a previously specified amount of time. The output type is not important.

Required Methods§

source

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

Create a [Stream][futures_util::stream::Stream], which returns a new item every Duration.

source

fn spawn( &self, future: Pin<Box<dyn Future<Output = ()> + Send + 'static, Global>> )

Spawn a new task or thread, which executes the given future.

Note

This is mainly used to run batch span processing in the background. Note, that the function does not return a handle. OpenTelemetry will use a different way to wait for the future to finish when TracerProvider gets shutdown. At the moment this happens by blocking the current thread. This means runtime implementations need to make sure they can still execute the given future even if the main thread is blocked.

source

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

Return a new future, which resolves after the specified Duration.

Implementors§

source§

impl Runtime for AsyncStd

Available on crate feature rt-async-std only.
§

type Interval = Interval

§

type Delay = Pin<Box<dyn Future<Output = ()> + Send + 'static, Global>>

source§

impl Runtime for Tokio

Available on crate feature rt-tokio only.
§

type Interval = IntervalStream

§

type Delay = Pin<Box<Sleep, Global>>

source§

impl Runtime for TokioCurrentThread

Available on crate feature rt-tokio-current-thread only.
§

type Interval = IntervalStream

§

type Delay = Pin<Box<Sleep, Global>>