Struct holochain::prelude::dependencies::kitsune_p2p_types::dependencies::futures::executor::LocalPool
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§
§impl LocalPool
impl LocalPool
pub fn spawner(&self) -> LocalSpawner
pub fn spawner(&self) -> LocalSpawner
Get a clonable handle to the pool as a Spawn
.
pub fn run(&mut self)
pub fn run(&mut self)
Run all tasks in the pool to completion.
use futures::executor::LocalPool;
let mut pool = 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.
pub fn run_until<F>(&mut self, future: F) -> <F as Future>::Outputwhere
F: Future,
pub fn run_until<F>(&mut self, future: F) -> <F as Future>::Outputwhere
F: Future,
Runs all the tasks in the pool until the given future completes.
use futures::executor::LocalPool;
let mut pool = LocalPool::new();
// run tasks in the pool until `my_app` completes
pool.run_until(my_app);
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.
pub fn try_run_one(&mut self) -> bool
pub fn try_run_one(&mut self) -> bool
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::executor::LocalPool;
use futures::task::LocalSpawnExt;
use futures::future::{ready, pending};
let mut pool = LocalPool::new();
let spawner = pool.spawner();
spawner.spawn_local(ready(())).unwrap();
spawner.spawn_local(ready(())).unwrap();
spawner.spawn_local(pending()).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!(!pool.try_run_one()); // 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.
pub fn run_until_stalled(&mut self)
pub fn run_until_stalled(&mut self)
Runs all tasks in the pool and returns if no more progress can be made on any task.
use futures::executor::LocalPool;
use futures::task::LocalSpawnExt;
use futures::future::{ready, pending};
let mut pool = LocalPool::new();
let spawner = pool.spawner();
spawner.spawn_local(ready(())).unwrap();
spawner.spawn_local(ready(())).unwrap();
spawner.spawn_local(pending()).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.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for LocalPool
impl !Send for LocalPool
impl !Sync for LocalPool
impl Unpin for LocalPool
impl !UnwindSafe for LocalPool
Blanket Implementations§
§impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.