[][src]Struct employer::Employer

pub struct Employer<K, V, D> { /* fields omitted */ }

An interface for spawning worker threads and storing their results

The description passed to Employer::new must implement the JobDescription trait.

Methods

impl<K, V, D> Employer<K, V, D>[src]

pub fn new(description: D) -> Self[src]

Create a new Employer with the given job description

impl<K, V, S, F> Employer<K, V, (S, F)> where
    (S, F): JobDescription<K, Output = V>, 
[src]

pub fn with_state(state: S, f: F) -> Self[src]

Create a new Employer wither the given shared state and job function

impl<K, V, D> Employer<K, V, D>[src]

pub fn get<'a, Q>(&'a self, input: &Q) -> Job<'a, K, V> where
    Q: Hash + Ord,
    K: Borrow<Q>, 
[src]

Get the job with the given input

pub fn wait_for<'a, Q>(&'a self, input: &Q) -> Option<OutputGuard<'a, K, V>> where
    Q: Hash + Ord,
    K: Borrow<Q>, 
[src]

Block the thread, wait for a job to finish, and get its result

Returns None if a job with the given input does not exist

pub fn finished<Q>(&self, input: &Q) -> bool where
    Q: Hash + Ord,
    K: Borrow<Q>, 
[src]

Check if the job with the given input has finished

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

Check the number of jobs that are in progress

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

Check the number of jobs that are in progress

pub fn finished_iter(&self) -> JobIter<K, V>[src]

Iterate over finished job input/output pairs

pub fn in_progress_inputs(&self) -> impl Iterator<Item = InputGuard<K, V>>[src]

Iterate over in_progress job inputs

pub fn finished_inputs(&self) -> impl Iterator<Item = InputGuard<K, V>>[src]

Iterate over finished job inputs

pub fn inputs(&self) -> impl Iterator<Item = InputGuard<K, V>>[src]

Iterate over all job inputs

pub fn outputs(&self) -> impl Iterator<Item = OutputGuard<K, V>>[src]

Iterate over finished job outputs

impl<K, V, D> Employer<K, V, D> where
    K: Ord + Hash + Clone + Send + Sync + 'static,
    V: Send + Sync + 'static,
    D: JobDescription<K, Output = V> + 'static, 
[src]

pub fn start(&self, input: K)[src]

Start a new job with the the given input if one with the same input is not in progress or finished

If you want to start the job even if one with the same input is already finished, use Employer::restart or Employer::restart_if.

pub fn restart(&self, input: K)[src]

Start a new job with the given input if one with the same input is not in progress

If you want to avoid starting a new job if one with the same input has already finished, use Employer::start.

pub fn restart_if<G>(&self, input: K, condition: G) where
    G: FnOnce(&V) -> bool
[src]

Start a new job with the given input if one with the same input is not in progress, and if it exists and is finished, the result satisfies the supplied condition

An example use case is if your job involves IO. In this case, your work function could return a Result, and the condition supplied to this function would be Result::is_err.

If you want to avoid starting a new job if one with the same input has already finished, use Employer::start.

pub fn remove<Q>(&self, input: &Q) where
    Q: Hash + Ord,
    K: Borrow<Q>, 
[src]

Remove a finished job with the given input

Trait Implementations

impl<K, V, D> Debug for Employer<K, V, D>[src]

impl<K, V, D> Default for Employer<K, V, D> where
    D: Default
[src]

impl<K, V, D> From<D> for Employer<K, V, D>[src]

impl<K, V, D> From<Employer<K, V, D>> for Arc<D>[src]

impl<'a, K, V, H> IntoIterator for &'a Employer<K, V, H>[src]

type Item = JobGuard<'a, K, V>

The type of the elements being iterated over.

type IntoIter = JobIter<'a, K, V>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<K, V, D> !RefUnwindSafe for Employer<K, V, D>

impl<K, V, D> Send for Employer<K, V, D> where
    D: Send + Sync,
    K: Send + Sync,
    V: Send + Sync

impl<K, V, D> Sync for Employer<K, V, D> where
    D: Send + Sync,
    K: Send + Sync,
    V: Send + Sync

impl<K, V, D> Unpin for Employer<K, V, D>

impl<K, V, D> !UnwindSafe for Employer<K, V, D>

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<!> for T[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.