LocalPool

Struct LocalPool 

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

A single-threaded task pool for polling futures to completion.

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

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

Implementations§

Source§

impl LocalPool

Source

pub fn new() -> Self

Create a new, empty pool of tasks.

Source

pub fn spawner(&self) -> LocalSpawner

Get a clonable handle to the pool as a Spawn.

Source

pub fn run<P: Park>(&mut self, park: &mut P, enter: &mut Enter)

Run all tasks in the pool to completion.

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

Source

pub fn run_until<P: Park, F: Future>( &mut self, park: &mut P, enter: &mut Enter, future: F, ) -> F::Output

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

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

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 one of the pool’s run or poll methods. While the function is running, however, all tasks in the pool will try to make progress.

Source

pub fn poll_pool(&mut self, cx: &mut Context<'_>) -> Poll<()>

Make progress on entire pool, polling each spawend task at most once.

Becomes Ready when all tasks are completed.

Source

pub fn spawn(&self, future: LocalFutureObj<'static, ()>)

Spawn future on pool

Trait Implementations§

Source§

impl Debug for LocalPool

Source§

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

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

impl Default for LocalPool

Source§

fn default() -> Self

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

impl LocalSpawn for LocalPool

Source§

fn spawn_local_obj( &mut self, future: LocalFutureObj<'static, ()>, ) -> Result<(), SpawnError>

Spawns a future that will be run to completion. Read more
Source§

fn status_local(&self) -> Result<(), SpawnError>

Determines whether the executor is able to spawn new tasks. Read more
Source§

impl Spawn for LocalPool

Source§

fn spawn_obj( &mut self, future: FutureObj<'static, ()>, ) -> Result<(), SpawnError>

Spawns a future that will be run to completion. Read more
Source§

fn status(&self) -> Result<(), SpawnError>

Determines whether the executor is able to spawn new tasks. 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<Sp> LocalSpawnExt for Sp
where Sp: LocalSpawn + ?Sized,

Source§

fn spawn_local<Fut>(&mut self, future: Fut) -> Result<(), SpawnError>
where Fut: Future<Output = ()> + 'static,

Spawns a task that polls the given future with output () to completion. Read more
Source§

impl<Sp> SpawnExt for Sp
where Sp: Spawn + ?Sized,

Source§

fn spawn<Fut>(&mut self, future: Fut) -> Result<(), SpawnError>
where Fut: Future<Output = ()> + Send + 'static,

Spawns a task that polls the given future with output () to completion. 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.