[][src]Function tokio_compat::runtime::run

pub fn run<F>(future: F) where
    F: Future01<Item = (), Error = ()> + Send + 'static, 
This is supported on (feature="rt-current-thread" or feature="rt-full") and feature="rt-full" only.

Start the Tokio runtime using the supplied futures 0.1 future to bootstrap execution.

This function is used to bootstrap the execution of a Tokio application. It does the following:

  • Start the Tokio runtime using a default configuration.
  • Spawn the given future onto the thread pool.
  • Block the current thread until the runtime shuts down.

Note that the function will not return immediately once future has completed. Instead it waits for the entire runtime to become idle.

See the module level documentation for more details.

Examples

use futures_01::{Future as Future01, Stream as Stream01};
use tokio_01::net::TcpListener;

let listener = TcpListener::bind(&addr).unwrap();

let server = listener.incoming()
    .map_err(|e| println!("error = {:?}", e))
    .for_each(|socket| {
        tokio_01::spawn(process(socket))
    });

tokio_compat::run(server);

Panics

This function panics if called from the context of an executor.