Trait Runtime

Source
pub trait Runtime:
    Clone
    + Send
    + Sync
    + 'static {
    // Required methods
    fn spawn<F>(&self, future: F)
       where F: Future<Output = ()> + Send + 'static;
    fn delay(
        &self,
        duration: Duration,
    ) -> impl Future<Output = ()> + Send + 'static;
}
Expand description

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

§Note

OpenTelemetry expects a multithreaded runtime because its types can move across threads. For this reason, this trait requires the Send and Sync bounds. Single-threaded runtimes can implement this trait in a way that spawns the tasks on the same thread as the calling code.

Required Methods§

Source

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

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 the caller shuts down.

At the moment, the shutdown 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) -> impl Future<Output = ()> + Send + 'static

Return a future that resolves after the specified Duration.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§