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.

use any_spawner::Executor;
// spawn a thread-safe Future
Executor::spawn(async { /* ... */ });
Source

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

Spawns a Future that cannot be sent across threads.

use any_spawner::Executor;

// spawn a thread-safe Future
Executor::spawn_local(async { /* ... */ });
Source

pub async fn tick()

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

Source

pub fn poll_local()

Polls the current async executor. Not all async executors support polling, so this function may not do anything.

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 an 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 an 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 an 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 an 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 an 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.

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

Source

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

Locally sets a custom executor as the executor used to spawn tasks in the current thread.

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

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