Trait WorkerMethods

Source
pub trait WorkerMethods<T, R> {
Show 13 methods // Required methods fn add_task(&self, task: T); fn add_tasks(&self, tasks: impl IntoIterator<Item = T>); fn get(&self) -> Option<R>; fn get_blocking(&self) -> Option<R>; fn cancel_tasks(&self); fn pending_tasks(&self) -> usize; // Provided methods fn get_iter(&self) -> impl Iterator<Item = R> { ... } fn get_iter_blocking(&self) -> impl Iterator<Item = R> { ... } fn get_vec(&self) -> Vec<R> { ... } fn get_vec_blocking(&self) -> Vec<R> { ... } fn get_buffered(&self, buffer: &mut [R]) -> usize { ... } fn get_buffered_blocking(&self, buffer: &mut [R]) -> usize { ... } fn reset(&self) { ... }
}
Expand description

Methods for interacting with a worker.

Required Methods§

Source

fn add_task(&self, task: T)

Add a task to the end of the queue. The task will be processed by one of the worker threads.

Source

fn add_tasks(&self, tasks: impl IntoIterator<Item = T>)

Add multiple tasks to the end of the queue. The tasks will be processed by the worker threads.

Source

fn get(&self) -> Option<R>

Return the next result. If no result is available, return None. This function will not block.

Source

fn get_blocking(&self) -> Option<R>

Return the next result. If no result is available block until a result is available. If no tasks are pending, return None.

Source

fn cancel_tasks(&self)

Cancel all tasks.

Source

fn pending_tasks(&self) -> usize

Return the number of pending tasks. This only includes tasks that have been added to the queue but have not started processing.

Provided Methods§

Source

fn get_iter(&self) -> impl Iterator<Item = R>

Return an iterator over all available results. This function will not block.

Source

fn get_iter_blocking(&self) -> impl Iterator<Item = R>

Returns an iterator over all results. This function will block until all tasks have been processed.

Source

fn get_vec(&self) -> Vec<R>

Receive all available results and return them in a vector. This function will not block.

Source

fn get_vec_blocking(&self) -> Vec<R>

Block until all tasks have been processed and return all results in a vector. This function will block until all tasks have been processed.

Source

fn get_buffered(&self, buffer: &mut [R]) -> usize

Write available results into the buffer and return the number of results written. If the buffer is too small to hold all available results, the remaining results will be left in the queue. This function will not block.

Source

fn get_buffered_blocking(&self, buffer: &mut [R]) -> usize

Write all results into the buffer and return the number of results written. If the buffer is too small to hold all results, the remaining results will be left in the queue. This function will block until all tasks have been processed or the buffer is full.

Source

fn reset(&self)

Clear the task queue, cancel all tasks and discard all results. This function will block until all tasks have been canceled.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, R> WorkerMethods<T, R> for BasicWorker<T, R>
where T: Send + 'static, R: Send + 'static,

Source§

impl<T, R> WorkerMethods<T, R> for CancelableWorker<T, R>
where T: Send + 'static, R: Send + 'static,

Source§

impl<T, R> WorkerMethods<T, R> for OrderedWorker<T, R>
where T: Send + 'static, R: Send + 'static,