Struct LocalPool
struct LocalPool { ... }
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
impl LocalPool
fn new() -> SelfCreate a new, empty pool of tasks.
fn spawner(self: &Self) -> LocalSpawnerGet a clonable handle to the pool as a
Spawn.fn run(self: &mut Self)Run all tasks in the pool to completion.
use LocalPool; let mut pool = new; // ... spawn some initial tasks using `spawn.spawn()` or `spawn.spawn_local()` // run *all* tasks in the pool to completion, including any newly-spawned ones. pool.run;The function will block the calling thread until all tasks in the pool are complete, including any spawned while running existing tasks.
fn run_until<F: Future>(self: &mut Self, future: F) -> <F as >::OutputRuns all the tasks in the pool until the given future completes.
use LocalPool; let mut pool = new; # let my_app = async ; // run tasks in the pool until `my_app` completes pool.run_until;The function will block the calling thread only until the future
fcompletes; 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.fn try_run_one(self: &mut Self) -> boolRuns all tasks and returns after completing one future or until no more progress can be made. Returns
trueif one future was completed,falseotherwise.use LocalPool; use LocalSpawnExt; use ; let mut pool = new; let spawner = pool.spawner; spawner.spawn_local.unwrap; spawner.spawn_local.unwrap; spawner.spawn_local.unwrap; // Run the two ready tasks and return true for them. pool.try_run_one; // returns true after completing one of the ready futures pool.try_run_one; // returns true after completing the other ready future // the remaining task can not be completed assert!; // returns falseThis function will not block the calling thread and will return the moment that there are no tasks left for which progress can be made or after exactly one task was completed; Remaining incomplete tasks in the pool can continue with further use of one of the pool's run or poll methods. Though only one task will be completed, progress may be made on multiple tasks.
fn run_until_stalled(self: &mut Self)Runs all tasks in the pool and returns if no more progress can be made on any task.
use LocalPool; use LocalSpawnExt; use ; let mut pool = new; let spawner = pool.spawner; spawner.spawn_local.unwrap; spawner.spawn_local.unwrap; spawner.spawn_local.unwrap; // Runs the two ready task and returns. // The empty task remains in the pool. pool.run_until_stalled;This function will not block the calling thread and will return the moment that there are no tasks left for which progress can be made; remaining incomplete tasks in the pool can continue with further use of one of the pool's run or poll methods. While the function is running, all tasks in the pool will try to make progress.
impl Debug for LocalPool
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for LocalPool
fn default() -> Self
impl Freeze for LocalPool
impl RefUnwindSafe for LocalPool
impl Send for LocalPool
impl Sync for LocalPool
impl Unpin for LocalPool
impl UnsafeUnpin for LocalPool
impl UnwindSafe for LocalPool
impl<T> Any for LocalPool
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for LocalPool
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for LocalPool
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for LocalPool
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for LocalPool
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for LocalPool
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for LocalPool
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>