pub trait AsyncLocalSpawner:
Yielder
+ Copy
+ 'static {
type JoinHandle<O>: LocalJoinHandle<O> + 'static
where O: 'static;
// Required method
fn spawn_local<F>(future: F) -> Self::JoinHandle<F::Output>
where F::Output: 'static,
F: Future + 'static;
// Provided method
fn spawn_local_detach<F>(future: F)
where F::Output: 'static,
F: Future + 'static { ... }
}Expand description
A spawner trait for spawning futures.
§Local-executor context (contract note)
A local spawn needs a thread-local executor somebody drives, and not every runtime has an ambient one. An implementation may panic when the current thread has no local-executor context to target:
tokio: panics outside aLocalSetorLocalRuntime(tokio’s own documentedspawn_localcontract).smol: always panics — smol has no ambient thread-local executor; drive asmol::LocalExecutoryourself and spawn onto it directly.embassy: always panics — its global spawner isSend-only.
Required Associated Types§
Sourcetype JoinHandle<O>: LocalJoinHandle<O> + 'static
where
O: 'static
type JoinHandle<O>: LocalJoinHandle<O> + 'static where O: 'static
The handle returned by the spawner when a future is spawned.
Required Methods§
Sourcefn spawn_local<F>(future: F) -> Self::JoinHandle<F::Output>
fn spawn_local<F>(future: F) -> Self::JoinHandle<F::Output>
Spawn a future.
Provided Methods§
Sourcefn spawn_local_detach<F>(future: F)
fn spawn_local_detach<F>(future: F)
Spawn a future and detach it.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl AsyncLocalSpawner for EmbassySpawner
Available on crate feature embassy only.
impl AsyncLocalSpawner for EmbassySpawner
embassy only.type JoinHandle<F> = JoinHandle<F> where F: 'static
Source§impl AsyncLocalSpawner for SmolSpawner
Available on crate feature smol only.§Panics
Both local-spawn methods always panic: smol has no ambient thread-local
executor to target, so a correct local spawn needs a smol::LocalExecutor
the caller owns and drives — spawn onto it directly instead. (Before 0.7
these methods spawned onto a temporary LocalExecutor that dropped at the
end of the statement, cancelling the task: a silent no-op for
spawn_local_detach, and a “task polled after completion” panic on
awaiting spawn_local’s handle. A loud, immediate panic replaces that
silent loss.)
impl AsyncLocalSpawner for SmolSpawner
smol only.§Panics
Both local-spawn methods always panic: smol has no ambient thread-local
executor to target, so a correct local spawn needs a smol::LocalExecutor
the caller owns and drives — spawn onto it directly instead. (Before 0.7
these methods spawned onto a temporary LocalExecutor that dropped at the
end of the statement, cancelling the task: a silent no-op for
spawn_local_detach, and a “task polled after completion” panic on
awaiting spawn_local’s handle. A loud, immediate panic replaces that
silent loss.)
type JoinHandle<O> = JoinHandle<O> where O: 'static
Source§impl AsyncLocalSpawner for TokioSpawner
Available on crate feature tokio only.
impl AsyncLocalSpawner for TokioSpawner
tokio only.type JoinHandle<F> = JoinHandle<F> where F: 'static
Source§impl AsyncLocalSpawner for WasmSpawner
Available on crate feature wasm only.
impl AsyncLocalSpawner for WasmSpawner
wasm only.