Struct tokio::runtime::Runtime
[−]
[src]
pub struct Runtime { /* fields omitted */ }
Handle to the Tokio runtime.
The Tokio runtime includes a reactor as well as an executor for running tasks.
See module level documentation for more details.
Methods
impl Runtime
[src]
pub fn new() -> Result<Self>
[src]
Create a new runtime instance with default configuration values.
See module level documentation for more details.
pub fn handle(&self) -> &Handle
[src]
Return a reference to the reactor handle for this runtime instance.
pub fn executor(&self) -> TaskExecutor
[src]
Return a handle to the runtime's executor.
ⓘImportant traits for &'a mut Wpub fn spawn<F>(&mut self, future: F) -> &mut Self where
F: Future<Item = (), Error = ()> + Send + 'static,
[src]
F: Future<Item = (), Error = ()> + Send + 'static,
Spawn a future onto the Tokio runtime.
This spawns the given future onto the runtime's executor, usually a thread pool. The thread pool is then responsible for polling the future until it completes.
See module level documentation for more details.
Examples
use tokio::runtime::Runtime; // Create the runtime let mut rt = Runtime::new().unwrap(); // Spawn a future onto the runtime rt.spawn(future::lazy(|| { println!("now running on a worker thread"); Ok(()) }));
Panics
This function panics if the spawn fails. Failure occurs if the executor is currently at capacity and is unable to spawn a new future.
pub fn shutdown_on_idle(self) -> Shutdown
[src]
Signals the runtime to shutdown once it becomes idle.
Returns a future that completes once the shutdown operation has completed.
This function can be used to perform a graceful shutdown of the runtime.
The runtime enters an idle state once all of the following occur.
- The thread pool has no tasks to execute, i.e., all tasks that were spawned have completed.
- The reactor is not managing any I/O resources.
See module level documentation for more details.
pub fn shutdown_now(self) -> Shutdown
[src]
Signals the runtime to shutdown immediately.
Returns a future that completes once the shutdown operation has completed.
This function will forcibly shutdown the runtime, causing any in-progress work to become canceled. The shutdown steps are:
- Drain any scheduled work queues.
- Drop any futures that have not yet completed.
- Drop the reactor.
Once the reactor has dropped, any outstanding I/O resources bound to that reactor will no longer function. Calling any method on them will result in an error.
See module level documentation for more details.
Trait Implementations
impl Debug for Runtime
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more