[][src]Struct autopool::WorkerPool

pub struct WorkerPool<In, Out, F> { /* fields omitted */ }

WorkerPool

This is a channels-oriented async worker pool. It's intended to be used with relatively long-running futures that all write out to the same output channel of type Out. The worker pool gathers all of that output in whatever order it appears, and sends it to the output channel.

The number of workers in this implementation is intended as a best effort, not a fixed count, with an eye towards being used in situations where we may want that number to go up or down over time based on the environment conditions.

You could imagine that a system under load might decide to back off on the number of open connections if it was experiencing resource contention, and conversely to add new workers if the queue has grown and we aren't at our max worker count.

I'm not incredibly concerned about allocations in this model; WorkerPool is a higher level abstraction than something like crossbeam.

Implementations

impl<In, Out, F> WorkerPool<In, Out, F> where
    In: Send + Sync + Clone + 'static,
    Out: Send + Sync + 'static,
    F: Future<Output = JobStatus> + Send + 'static, 
[src]

pub fn new(task: fn(_: Job<In, Out>) -> F) -> Self[src]

pub fn new_with_config(
    task: fn(_: Job<In, Out>) -> F,
    config: WorkerPoolConfig<In>
) -> Self
[src]

pub fn cur_workers(&self) -> usize[src]

Number of workers currently working This is the number of workers we haven't tried to stop yet plus the workers that haven't noticed they were told to stop.

pub fn target_workers(&self) -> usize[src]

Target number of workers

pub fn at_target_worker_count(&self) -> bool[src]

Whether the current number of workers is the target number of workers Adjusted for the number of workers that we have TOLD to stop but have not actually gotten around to stopping yet.

pub fn working(&self) -> bool[src]

pub fn set_target_workers(&mut self, n: usize)[src]

Sets the target number of workers. Does not stop in-progress workers.

pub fn push(&mut self, task: In)[src]

Add a new task to the back of the queue

pub fn command(&mut self, command: WorkerPoolCommand)[src]

pub fn work(&mut self) -> WorkerPoolStatus<Out>[src]

Auto Trait Implementations

impl<In, Out, F> !RefUnwindSafe for WorkerPool<In, Out, F>

impl<In, Out, F> Send for WorkerPool<In, Out, F> where
    In: Send,
    Out: Send

impl<In, Out, F> Sync for WorkerPool<In, Out, F> where
    In: Sync,
    Out: Send

impl<In, Out, F> Unpin for WorkerPool<In, Out, F> where
    In: Unpin

impl<In, Out, F> !UnwindSafe for WorkerPool<In, Out, F>

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.