[][src]Function tokio_executor::spawn

pub fn spawn<T>(future: T) where
    T: Future<Item = (), Error = ()> + Send + 'static, 

Submits a future for execution on the default executor -- usually a threadpool.

Futures are lazy constructs. When they are defined, no work happens. In order for the logic defined by the future to be run, the future must be spawned on an executor. This function is the easiest way to do so.

This function must be called from an execution context, i.e. from a future that has been already spawned onto an executor.

Once spawned, the future will execute. The details of how that happens is left up to the executor instance. If the executor is a thread pool, the future will be pushed onto a queue that a worker thread polls from. If the executor is a "current thread" executor, the future might be polled immediately from within the call to spawn or it might be pushed onto an internal queue.


This function will panic if the default executor is not set or if spawning onto the default executor returns an error. To avoid the panic, use the DefaultExecutor handle directly.


use futures::future::lazy;

spawn(lazy(|| {
    println!("running on the default executor");