[][src]Struct poolparty::StoppableThreadPool

pub struct StoppableThreadPool<PoolError> where
    PoolError: Send + Sync + 'static, 
{ /* fields omitted */ }

Added functionality for the futures::executor::ThreadPool futures executor.

Futures will be spawned to and executed by the internal and exchangeable ThreadPool instance, but in such a way that all spawned futures are asked to stop on user request or in case any of them returns an error.

A notable difference to futures:executor::ThreadPool is that the user spawns futures of type Output<Result(),T> here instead of type Output<()>.

Caveats: If you do not call observe().await once all desired futures are spawned or if you spawn additional futures after the first observe().await the stopping mechanism won't work. In other words, instances cannot be "reused" after they were being observed for the first time. For now no measures are in place to prevent a user from doing this (maybe in a future version).

Also note that spawned tasks can not be cancelled instantly. They will stop executing the next time they yield to the executor.

Implementations

impl<PoolError> StoppableThreadPool<PoolError> where
    PoolError: Send + Sync + 'static, 
[src]

pub fn new() -> Result<StoppableThreadPool<PoolError>, Error>[src]

Create a new StoppableThreadPool instance using a default futures ThreadPool executor instance.

pub fn new_with_pool(pool: ThreadPool) -> StoppableThreadPool<PoolError>[src]

Create a new StoppableThreadPool instance using a user supplied futures ThreadPool executor instance.

pub fn with_pool(&mut self, pool: ThreadPool) -> &mut Self[src]

Change the underlying futures ThreadPool executor instance.

pub fn spawn<Fut>(&mut self, future: Fut) -> &mut Self where
    Fut: Future<Output = Result<(), PoolError>> + Send + 'static, 
[src]

Start executing a future right away.

pub async fn observe(&self) -> Result<(), PoolError>[src]

Ensure that all spawned tasks are canceled on individual task error or any stop() request issued by the user. Call this function once all tasks are spawned. A task that fails before a call to observe() is being awaited will still trigger a stop as soon as you actually start awaiting here.

pub async fn stop(&self, why: PoolError)[src]

Stop the execution of all spawned tasks.

Auto Trait Implementations

impl<PoolError> RefUnwindSafe for StoppableThreadPool<PoolError>[src]

impl<PoolError> Send for StoppableThreadPool<PoolError>[src]

impl<PoolError> Sync for StoppableThreadPool<PoolError>[src]

impl<PoolError> Unpin for StoppableThreadPool<PoolError>[src]

impl<PoolError> UnwindSafe for StoppableThreadPool<PoolError>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.