pub struct LocalPool<'a, Ret = ()> { /* 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

Create a new, empty pool of tasks.

Run all tasks in the pool to completion.


use minimal_executor::LocalPool;

let mut pool: LocalPool<'_, ()> = LocalPool::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.

Runs all tasks and returns after completing one future or until no more progress can be made. Returns true if one future was completed, false otherwise.


use futures::task::LocalSpawnExt;
use futures::future::{ready, pending};
use minimal_executor::LocalPool;

let mut pool: LocalPool<'_, ()> = LocalPool::new();
pool.spawn(Box::pin(ready(())));
pool.spawn(Box::pin(ready(())));
pool.spawn(Box::pin(pending()));

// 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!(pool.try_run_one().is_pending()); // returns false

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

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.