[−][src]Struct poolparty::StoppableThreadPool
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]
PoolError: Send + Sync + 'static,
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]
Fut: Future<Output = Result<(), PoolError>> + Send + 'static,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,