Task queue
Description
Parallel execution of the task queue with the ability to add new tasks inside the running tasks
Examples
let thread_count = 2;
let queue_type = Stack;
let task_queue = new;
where
thread_count
- the number of threads that execute tasks in parallel
queue_type
-
determines at the beginning or at the end of the queue the task will be added (Available values: Queue, Stack)
In order to add a task to the queue, you need to implement the trait RunTask
. The third argument task_receiver
is used to add new tasks. Method run
returns TaskControlCommand
, availabale values Continue
- default value that does not affect the operation of the queue in any way, Abort
- reset outstanding tasks and do not take new ones, the task queue will no longer execute tasks added externally.
// Add new task
task_queue.add_task?;
task_queue.add_task?;
// Cancel tasks and wait for the completion of task processing (Analogue - TaskControlCommand::Abort)
task_queue.abort?;
// Wait untill all tasks are completed
task_queue.join?;
! If you do not use abort
/ join
, drop will be used, but panics from worker processes are not handled, use join instead.