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
.
use any_spawner::Executor;
// spawn a thread-safe Future
Executor::spawn(async { /* ... */ });
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.
use any_spawner::Executor;
// spawn a thread-safe Future
Executor::spawn_local(async { /* ... */ });
Sourcepub fn poll_local()
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
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 an 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 an 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 an 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 an 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 an 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.
Returns Err(_)
if an 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>
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.