tokio_io_pool

Struct Runtime

Source
pub struct Runtime { /* private fields */ }
Expand description

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.

Implementations§

Source§

impl Runtime

Source

pub fn new() -> Self

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).

Source

pub fn handle(&self) -> &Handle

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.

Source

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

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.

Source

pub fn spawn_all<S>( &self, stream: S, ) -> impl Future<Item = (), Error = StreamSpawnError<<S as Stream>::Error>>
where S: Stream, <S as Stream>::Item: Future<Item = (), Error = ()> + Send + 'static,

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.

Source

pub fn block_on<F, R, E>(&mut self, future: F) -> Result<R, E>
where F: Send + 'static + Future<Item = R, Error = E>, R: Send + 'static, E: Send + 'static,

Run the given future on the current thread, and dispatch any child futures spawned with tokio::spawn onto the 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.

Note that the top-level future is executed using Future::wait, and thus does not provide access to timers, clocks, or other tokio runtime goodies.

Source

pub fn shutdown(self)

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.

Source

pub fn shutdown_on_idle(self)

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§

Source§

impl Debug for Runtime

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Runtime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Runtime

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.