Struct OrderedWorker

Source
pub struct OrderedWorker<T, R>
where T: Send + 'static, R: Send + 'static,
{ /* private fields */ }
Expand description

A worker that processes tasks in parallel using multiple worker threads. The results are returned in same order as the tasks were added.

Trait Implementations§

Source§

impl<T, R, F> WorkerInit<T, R, F> for OrderedWorker<T, R>
where T: Send + 'static, R: Send + 'static, F: Fn(T) -> R + Send + Copy + 'static,

Source§

fn with_num_threads(num_worker_threads: usize, worker_function: F) -> Self

Create a new worker with a given number of worker threads and a worker function. Spawns worker threads that will process tasks from the queue using the worker function.
Source§

fn new(worker_function: F) -> Self

Create a new worker with a given worker function. The number of worker threads will be set to the number of available logical cores minus one. Spawns worker threads that will process tasks from the queue using the worker function.
Source§

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

Source§

fn cancel_tasks(&self)

Clear the task queue. Ongoing tasks will not be canceled. Results of ongoing and already completed tasks will remain unaffected.

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 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.
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.

Auto Trait Implementations§

§

impl<T, R> !Freeze for OrderedWorker<T, R>

§

impl<T, R> !RefUnwindSafe for OrderedWorker<T, R>

§

impl<T, R> Send for OrderedWorker<T, R>

§

impl<T, R> !Sync for OrderedWorker<T, R>

§

impl<T, R> Unpin for OrderedWorker<T, R>
where R: Unpin,

§

impl<T, R> UnwindSafe for OrderedWorker<T, R>
where R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.