pub trait Spawn:
Send
+ Sync
+ 'static {
// Required methods
fn spawn(&self, fut: BoxFuture<()>);
fn spawn_blocking(&self, task: Box<dyn FnOnce() + Send + 'static>);
}Expand description
An executor that runs futures away from the tick loop.
Implementations own their worker threads and outlive every future they are
handed, so Self::spawn is fire-and-forget: a task that wants to report
back to the world pushes a Command onto the
CommandQueue, which the next tick drains
on the main thread.
Required Methods§
Sourcefn spawn(&self, fut: BoxFuture<()>)
fn spawn(&self, fut: BoxFuture<()>)
Run fut to completion on the executor and return immediately.
Dropping the returned unit does not cancel the task; there is no handle, by design. Cancellation, timeouts, and result delivery are the future’s own business, which keeps the seam free of executor-specific join-handle types.
Sourcefn spawn_blocking(&self, task: Box<dyn FnOnce() + Send + 'static>)
fn spawn_blocking(&self, task: Box<dyn FnOnce() + Send + 'static>)
Run a blocking closure on the executor’s blocking pool.
For work that parks the calling thread (a synchronous file read, a platform dialog with no async form). Implementations that have no separate pool may run it on a plain thread.