Struct futures::executor::LocalPool [−][src]
pub struct LocalPool { /* fields omitted */ }
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
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_obj
.
Methods
impl LocalPool
[src]
impl LocalPool
pub fn new() -> LocalPool
[src]
pub fn new() -> LocalPool
Create a new, empty pool of tasks.
pub fn executor(&self) -> LocalExecutor
[src]
pub fn executor(&self) -> LocalExecutor
Get a clonable handle to the pool as an executor.
pub fn run<Exec>(&mut self, exec: &mut Exec) where
Exec: Executor,
[src]
pub fn run<Exec>(&mut self, exec: &mut Exec) where
Exec: 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.
pub fn run_until<F, Exec>(
&mut self,
future: F,
exec: &mut Exec
) -> <F as Future>::Output where
Exec: Executor,
F: Future,
[src]
pub fn run_until<F, Exec>(
&mut self,
future: F,
exec: &mut Exec
) -> <F as Future>::Output where
Exec: Executor,
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.
Trait Implementations
impl Debug for LocalPool
[src]
impl Debug for LocalPool
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl Default for LocalPool
[src]
impl Default for LocalPool
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
ⓘImportant traits for &'a mut Ifn borrow(&self) -> &T
[src]
fn borrow(&self) -> &T
Immutably borrows from an owned value. Read more
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
ⓘImportant traits for &'a mut Ifn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more