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§
sourcetype JoinError: Debug + Display + OptionalSend
type JoinError: Debug + Display + OptionalSend
The error type of Self::JoinHandle
.
sourcetype JoinHandle<T: OptionalSend + 'static>: Future<Output = Result<T, Self::JoinError>> + OptionalSend + OptionalSync + Unpin
type JoinHandle<T: OptionalSend + 'static>: Future<Output = Result<T, Self::JoinError>> + OptionalSend + OptionalSync + Unpin
The return type of Self::spawn
.
sourcetype Sleep: Future<Output = ()> + OptionalSend + OptionalSync
type Sleep: Future<Output = ()> + OptionalSend + OptionalSync
The type that enables the user to sleep in an asynchronous runtime.
sourcetype TimeoutError: Debug + Display + OptionalSend
type TimeoutError: Debug + Display + OptionalSend
The timeout error type.
sourcetype Timeout<R, T: Future<Output = R> + OptionalSend>: Future<Output = Result<R, Self::TimeoutError>> + OptionalSend
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
.
sourcetype ThreadLocalRng: Rng
type ThreadLocalRng: Rng
Type of a thread-local random number generator.
sourcetype OneshotSender<T: OptionalSend>: AsyncOneshotSendExt<T> + OptionalSend + OptionalSync + Debug + Sized
type OneshotSender<T: OptionalSend>: AsyncOneshotSendExt<T> + OptionalSend + OptionalSync + Debug + Sized
Type of a oneshot
sender.
sourcetype OneshotReceiverError: Error + OptionalSend
type OneshotReceiverError: Error + OptionalSend
Type of a oneshot
receiver error.
sourcetype OneshotReceiver<T: OptionalSend>: OptionalSend + OptionalSync + Future<Output = Result<T, Self::OneshotReceiverError>> + Unpin
type OneshotReceiver<T: OptionalSend>: OptionalSend + OptionalSync + Future<Output = Result<T, Self::OneshotReceiverError>> + Unpin
Type of a oneshot
receiver.
Required Methods§
sourcefn spawn<T>(future: T) -> Self::JoinHandle<T::Output>
fn spawn<T>(future: T) -> Self::JoinHandle<T::Output>
Spawn a new task.
sourcefn sleep_until(deadline: Self::Instant) -> Self::Sleep
fn sleep_until(deadline: Self::Instant) -> Self::Sleep
Wait until deadline
is reached.
sourcefn timeout<R, F: Future<Output = R> + OptionalSend>(
duration: Duration,
future: F
) -> Self::Timeout<R, F>
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.
sourcefn timeout_at<R, F: Future<Output = R> + OptionalSend>(
deadline: Self::Instant,
future: F
) -> Self::Timeout<R, F>
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.
sourcefn is_panic(join_error: &Self::JoinError) -> bool
fn is_panic(join_error: &Self::JoinError) -> bool
Check if the Self::JoinError
is panic
.
sourcefn thread_rng() -> Self::ThreadLocalRng
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.
sourcefn oneshot<T>() -> (Self::OneshotSender<T>, Self::OneshotReceiver<T>)where
T: OptionalSend,
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.