[][src]Function tokio_io_pool::run

pub fn run<F>(future: F) where
    F: Future<Output = ()> + Send + 'static, 

Execute the given future and spawn any child futures onto a newly created I/O thread pool.

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

  • Start the Tokio I/O pool using a default configuration.
  • Configure Tokio to make any future spawned with tokio::spawn spawn on the pool.
  • Run the given future to completion on the current thread.
  • Block the current thread until the pool becomes idle.

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

Examples

use tokio::net::TcpListener;

let server = async move {
    let mut listener = TcpListener::bind(addr).await.unwrap();
    loop {
        let (socket, _) = listener.accept().await.expect("acccept failed");
        tokio::spawn(process(socket));
    }
};

tokio_io_pool::run(server);