pub fn run<F>(future: F)
Expand description
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. Note also that the top-level future will be executed with
Runtime::block_on
, which calls Future::wait
, and thus does not provide access to timers,
clocks, or other tokio runtime goodies.
ยงExamples
use tokio::net::TcpListener;
let listener = TcpListener::bind(&addr).unwrap();
let server = listener.incoming()
.map_err(|e| println!("error = {:?}", e))
.for_each(|socket| {
tokio::spawn(process(socket))
});
tokio_io_pool::run(server);