[][src]Struct tokio_io_pool::Runtime

pub struct Runtime { /* fields omitted */ }

An I/O-oriented thread pool for executing futures.

Each thread in the pool has its own I/O reactor, and futures are spawned onto threads round-robin. Futures do not (currently) move between threads in the pool once spawned, and any new futures spawned (using tokio::spawn) inside futures are scheduled on the same worker as the original future.

Methods

impl Runtime[src]

pub fn new() -> Self[src]

Create a new thread pool with parameters from a default Builder and return a handle to it.

Panics

Panics if enough threads could not be spawned (see Builder::build).

pub fn handle(&self) -> &Handle[src]

Return a reference to the pool.

The returned handle reference can be cloned in order to get an owned value of the handle. This handle can be used to spawn additional futures onto the pool from other threads.

pub fn spawn<F>(&self, future: F) -> Result<&Self, SpawnError> where
    F: Future<Output = ()> + Send + 'static, 
[src]

Spawn a future onto a runtime in the pool.

This spawns the given future onto a single thread runtime's executor. That thread is then responsible for polling the future until it completes.

#[must_use] pub fn spawn_all<S>(
    &self,
    stream: S
) -> impl Future<Output = Result<(), StreamSpawnError<<S as TryStream>::Error>>> where
    S: TryStream,
    <S as TryStream>::Ok: Future<Output = ()> + Send + 'static, 
[src]

Spawn all futures yielded by a stream onto the pool.

This produces a future that accepts futures from a Stream and spawns them all onto the pool round-robin.

pub fn block_on<F, O>(&mut self, future: F) -> O where
    F: Send + 'static + Future<Output = O>,
    O: Send + 'static, 
[src]

Run the given future on the pool, and dispatch any child futures spawned with tokio::spawn onto the entire I/O pool.

Note that child futures of futures that are already running on the pool will be executed on the same pool thread as their parent. Only the "top-level" calls to tokio::spawn are scheduled to the thread pool as a whole.

The current thread will be blocked until the given future resolves.

pub fn shutdown(self)[src]

Shut down the pool as soon as possible.

Note that once this method has been called, attempts to spawn additional futures onto the pool through an outstanding Handle may fail. Futures that have not yet resolved will be dropped.

The pool will only terminate once any currently-running futures return NotReady.

pub fn shutdown_on_idle(self)[src]

Shut down the pool once all spawned futures have completed.

Note that once this method has been called, attempts to spawn additional futures onto the pool through an outstanding Handle may fail.

Trait Implementations

impl Default for Runtime[src]

impl Drop for Runtime[src]

impl Debug for Runtime[src]

Auto Trait Implementations

impl Send for Runtime

impl Sync for Runtime

impl Unpin for Runtime

impl !RefUnwindSafe for Runtime

impl !UnwindSafe for Runtime

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]