pub struct Executor;Expand description
A global async executor that can spawn tasks.
Implementations§
Source§impl Executor
impl Executor
Sourcepub fn spawn(fut: impl Future<Output = ()> + Send + 'static)
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.
Sourcepub fn spawn_local(fut: impl Future<Output = ()> + 'static)
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.
Sourcepub async fn tick()
pub async fn tick()
Waits until the next “tick” of the current async executor. Respects the global executor.
Sourcepub fn poll_local()
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
impl Executor
Sourcepub fn init_tokio() -> Result<(), ExecutorError>
Available on crate feature tokio only.
pub fn init_tokio() -> Result<(), ExecutorError>
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.
Sourcepub fn init_wasm_bindgen() -> Result<(), ExecutorError>
Available on crate feature wasm-bindgen only.
pub fn init_wasm_bindgen() -> Result<(), ExecutorError>
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.
Sourcepub fn init_glib() -> Result<(), ExecutorError>
Available on crate feature glib only.
pub fn init_glib() -> Result<(), ExecutorError>
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.
Sourcepub fn init_futures_executor() -> Result<(), ExecutorError>
Available on crate feature futures-executor only.
pub fn init_futures_executor() -> Result<(), ExecutorError>
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.
Sourcepub fn init_async_executor() -> Result<(), ExecutorError>
Available on crate feature async-executor only.
pub fn init_async_executor() -> Result<(), ExecutorError>
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.
Sourcepub fn init_custom_executor(
custom_executor: impl CustomExecutor + Send + Sync + 'static,
) -> Result<(), ExecutorError>
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.
Sourcepub fn init_local_custom_executor(
custom_executor: impl CustomExecutor + 'static,
) -> Result<(), ExecutorError>
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.