Executor

Struct Executor 

Source
pub struct Executor;
Expand description

A global async executor that can spawn tasks.

Implementations§

Source§

impl Executor

Source

pub fn spawn(fut: impl Future<Output = ()> + Send + 'static)

Spawns a thread-safe Future.

Uses the globally configured executor. Panics if no global executor has been initialized.

Source

pub fn spawn_local(fut: impl Future<Output = ()> + 'static)

Spawns a Future that cannot be sent across threads.

Uses the globally configured executor. Panics if no global executor has been initialized.

Source

pub async fn tick()

Waits until the next “tick” of the current async executor. Respects the global executor.

Source

pub fn poll_local()

Polls the global async executor.

Uses the globally configured executor. Does nothing if the global executor does not support polling.

Source§

impl Executor

Source

pub fn init_tokio() -> Result<(), ExecutorError>

Available on crate feature tokio only.

Globally sets the tokio runtime as the executor used to spawn tasks.

Returns Err(_) if a global executor has already been set.

Requires the tokio feature to be activated on this crate.

Source

pub fn init_wasm_bindgen() -> Result<(), ExecutorError>

Available on crate feature wasm-bindgen only.

Globally sets the [wasm-bindgen-futures] runtime as the executor used to spawn tasks.

Returns Err(_) if a global executor has already been set.

Requires the wasm-bindgen feature to be activated on this crate.

Source

pub fn init_glib() -> Result<(), ExecutorError>

Available on crate feature glib only.

Globally sets the glib runtime as the executor used to spawn tasks.

Returns Err(_) if a global executor has already been set.

Requires the glib feature to be activated on this crate.

Source

pub fn init_futures_executor() -> Result<(), ExecutorError>

Available on crate feature futures-executor only.

Globally sets the futures executor as the executor used to spawn tasks, lazily creating a thread pool to spawn tasks into.

Returns Err(_) if a global executor has already been set.

Requires the futures-executor feature to be activated on this crate.

Source

pub fn init_async_executor() -> Result<(), ExecutorError>

Available on crate feature async-executor only.

Globally sets the async_executor executor as the executor used to spawn tasks, lazily creating a thread pool to spawn tasks into.

Returns Err(_) if a global executor has already been set.

Requires the async-executor feature to be activated on this crate.

Source

pub fn init_custom_executor( custom_executor: impl CustomExecutor + Send + Sync + 'static, ) -> Result<(), ExecutorError>

Globally sets a custom executor as the executor used to spawn tasks.

Requires the custom executor to be Send + Sync as it will be stored statically.

Returns Err(_) if a global executor has already been set.

Source

pub fn init_local_custom_executor( custom_executor: impl CustomExecutor + 'static, ) -> Result<(), ExecutorError>

Sets a custom executor for the current thread only.

This overrides the global executor for calls to spawn, spawn_local, and poll_local made from the current thread. It does not affect other threads or the global state.

The provided custom_executor must implement CustomExecutor and 'static, but does not need to be Send or Sync.

Returns Err(ExecutorError::AlreadySet) if a local executor has already been set for this thread.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more