pub struct OrderedWorker<T, R>{ /* 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>
impl<T, R, F> WorkerInit<T, R, F> for OrderedWorker<T, R>
Source§fn with_num_threads(num_worker_threads: usize, worker_function: F) -> Self
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§impl<T, R> WorkerMethods<T, R> for OrderedWorker<T, R>
impl<T, R> WorkerMethods<T, R> for OrderedWorker<T, R>
Source§fn cancel_tasks(&self)
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)
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>)
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>
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>
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
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>
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>
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>
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>
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
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
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more