Trait openraft::async_runtime::AsyncRuntime

source ·
pub trait AsyncRuntime: Debug + Default + PartialEq + Eq + OptionalSend + OptionalSync + 'static {
    type JoinError: Debug + Display + OptionalSend;
    type JoinHandle<T: OptionalSend + 'static>: Future<Output = Result<T, Self::JoinError>> + OptionalSend + OptionalSync + Unpin;
    type Sleep: Future<Output = ()> + OptionalSend + OptionalSync;
    type Instant: Instant;
    type TimeoutError: Debug + Display + OptionalSend;
    type Timeout<R, T: Future<Output = R> + OptionalSend>: Future<Output = Result<R, Self::TimeoutError>> + OptionalSend;
    type ThreadLocalRng: Rng;
    type OneshotSender<T: OptionalSend>: AsyncOneshotSendExt<T> + OptionalSend + OptionalSync + Debug + Sized;
    type OneshotReceiverError: Error + OptionalSend;
    type OneshotReceiver<T: OptionalSend>: OptionalSend + OptionalSync + Future<Output = Result<T, Self::OneshotReceiverError>> + Unpin;

    // Required methods
    fn spawn<T>(future: T) -> Self::JoinHandle<T::Output>
       where T: Future + OptionalSend + 'static,
             T::Output: OptionalSend + 'static;
    fn sleep(duration: Duration) -> Self::Sleep;
    fn sleep_until(deadline: Self::Instant) -> Self::Sleep;
    fn timeout<R, F: Future<Output = R> + OptionalSend>(
        duration: Duration,
        future: F
    ) -> Self::Timeout<R, F>;
    fn timeout_at<R, F: Future<Output = R> + OptionalSend>(
        deadline: Self::Instant,
        future: F
    ) -> Self::Timeout<R, F>;
    fn is_panic(join_error: &Self::JoinError) -> bool;
    fn thread_rng() -> Self::ThreadLocalRng;
    fn oneshot<T>() -> (Self::OneshotSender<T>, Self::OneshotReceiver<T>)
       where T: OptionalSend;
}
Expand description

A trait defining interfaces with an asynchronous runtime.

The intention of this trait is to allow an application using this crate to bind an asynchronous runtime that suits it the best.

Some additional related functions are also exposed by this trait.

§Note

The default asynchronous runtime is tokio.

Required Associated Types§

source

type JoinError: Debug + Display + OptionalSend

The error type of Self::JoinHandle.

source

type JoinHandle<T: OptionalSend + 'static>: Future<Output = Result<T, Self::JoinError>> + OptionalSend + OptionalSync + Unpin

The return type of Self::spawn.

source

type Sleep: Future<Output = ()> + OptionalSend + OptionalSync

The type that enables the user to sleep in an asynchronous runtime.

source

type Instant: Instant

A measurement of a monotonically non-decreasing clock.

source

type TimeoutError: Debug + Display + OptionalSend

The timeout error type.

source

type Timeout<R, T: Future<Output = R> + OptionalSend>: Future<Output = Result<R, Self::TimeoutError>> + OptionalSend

The timeout type used by Self::timeout and Self::timeout_at that enables the user to await the outcome of a Future.

source

type ThreadLocalRng: Rng

Type of a thread-local random number generator.

source

type OneshotSender<T: OptionalSend>: AsyncOneshotSendExt<T> + OptionalSend + OptionalSync + Debug + Sized

Type of a oneshot sender.

source

type OneshotReceiverError: Error + OptionalSend

Type of a oneshot receiver error.

source

type OneshotReceiver<T: OptionalSend>: OptionalSend + OptionalSync + Future<Output = Result<T, Self::OneshotReceiverError>> + Unpin

Type of a oneshot receiver.

Required Methods§

source

fn spawn<T>(future: T) -> Self::JoinHandle<T::Output>
where T: Future + OptionalSend + 'static, T::Output: OptionalSend + 'static,

Spawn a new task.

source

fn sleep(duration: Duration) -> Self::Sleep

Wait until duration has elapsed.

source

fn sleep_until(deadline: Self::Instant) -> Self::Sleep

Wait until deadline is reached.

source

fn timeout<R, F: Future<Output = R> + OptionalSend>( duration: Duration, future: F ) -> Self::Timeout<R, F>

Require a Future to complete before the specified duration has elapsed.

source

fn timeout_at<R, F: Future<Output = R> + OptionalSend>( deadline: Self::Instant, future: F ) -> Self::Timeout<R, F>

Require a Future to complete before the specified instant in time.

source

fn is_panic(join_error: &Self::JoinError) -> bool

Check if the Self::JoinError is panic.

source

fn thread_rng() -> Self::ThreadLocalRng

Get the random number generator to use for generating random numbers.

§Note

This is a per-thread instance, which cannot be shared across threads or sent to another thread.

source

fn oneshot<T>() -> (Self::OneshotSender<T>, Self::OneshotReceiver<T>)
where T: OptionalSend,

Creates a new one-shot channel for sending single values.

The function returns separate “send” and “receive” handles. The Sender handle is used by the producer to send the value. The Receiver handle is used by the consumer to receive the value.

Each handle can be used on separate tasks.

Object Safety§

This trait is not object safe.

Implementors§