Skip to main content

SpawnableFuture

Trait SpawnableFuture 

Source
pub trait SpawnableFuture<T>:
    Future<Output = T>
    + Send
    + 'static { }
Expand description

The bound a future must satisfy to be handed to BackgroundTasks::spawn_async — mirrored as a trait (rather than written out at every call site) so both spawn_async itself and the scheduler’s AsyncExt::detach/ AsyncEventWriter share one definition instead of duplicating the native/web split.

Native futures cross to a worker thread, so they must be Send; web futures run on the browser’s microtask queue on the same thread, so they don’t need to be — which is what lets a web future capture !Send browser-bound types (JsValue, a web_sys handle, …).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, F: Future<Output = T> + Send + 'static> SpawnableFuture<T> for F

Available on non-WebAssembly only.