futures::executor

Struct LocalPool

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

A single-threaded task pool.

This executor allows you to multiplex any number of tasks onto a single thread. It’s appropriate for strictly I/O-bound tasks that do very little work in between I/O actions.

To get a handle to the pool that implements Executor, use the executor() method. Because the executor is single-threaded, it supports a special form of task spawning for non-Send futures, via spawn_local.

Implementations§

Source§

impl LocalPool

Source

pub fn new() -> LocalPool

Create a new, empty pool of tasks.

Source

pub fn executor(&self) -> LocalExecutor

Get a clonable handle to the pool as an executor.

Source

pub fn run(&mut self, exec: &mut dyn Executor)

Run all tasks in the pool to completion.

The given executor, exec, is used as the default executor for any newly-spawned tasks. You can route these additional tasks back into the LocalPool by using its executor handle:


let mut pool = LocalPool::new();
let mut exec = pool.executor();

// ... spawn some initial tasks using `exec.spawn()` or `exec.spawn_local()`

// run *all* tasks in the pool to completion, including any newly-spawned ones.
pool.run(&mut exec);

The function will block the calling thread until all tasks in the pool are complete, including any spawned while running existing tasks.

Source

pub fn run_until<F>( &mut self, f: F, exec: &mut dyn Executor, ) -> Result<<F as Future>::Item, <F as Future>::Error>
where F: Future,

Runs all the tasks in the pool until the given future completes.

The given executor, exec, is used as the default executor for any newly-spawned tasks. You can route these additional tasks back into the LocalPool by using its executor handle:


let mut pool = LocalPool::new();
let mut exec = pool.executor();

// run tasks in the pool until `my_app` completes, by default spawning
// further tasks back onto the pool
pool.run_until(my_app, &mut exec);

The function will block the calling thread only until the future f completes; there may still be incomplete tasks in the pool, which will be inert after the call completes, but can continue with further use of run or run_until. While the function is running, however, all tasks in the pool will try to make progress.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.