pub struct TaskQueue { /* private fields */ }Expand description
Task queue.
This queue spawns worker threads for executing registered tasks.
§Examples
use tasque::TaskQueue;
let queue = TaskQueue::new();
queue.enqueue(|| println!("Hello"));
queue.enqueue(|| println!("World"));Implementations§
Source§impl TaskQueue
impl TaskQueue
Sourcepub fn new() -> Self
pub fn new() -> Self
Makes a new TaskQueue instance.
This is equivalent to TaskQueueBuilder::new().finish().
Examples found in repository?
examples/metrics.rs (line 9)
8fn main() {
9 let queue = TaskQueue::new();
10 queue.enqueue(|| thread::sleep(Duration::from_millis(1)));
11 queue.enqueue(|| thread::sleep(Duration::from_millis(50)));
12 queue.enqueue(|| thread::sleep(Duration::from_millis(1000)));
13 thread::sleep(Duration::from_millis(100));
14
15 println!(
16 "{}",
17 prometrics::default_gatherer()
18 .lock()
19 .unwrap()
20 .gather()
21 .to_text()
22 );
23}Sourcepub fn enqueue<F>(&self, task: F)
pub fn enqueue<F>(&self, task: F)
Enqueues a task.
The task will be executed by a worker thread.
If the thread panics while executing the task, it will be automatically restarted. Note that the task will not be retried in such case.
Examples found in repository?
examples/metrics.rs (line 10)
8fn main() {
9 let queue = TaskQueue::new();
10 queue.enqueue(|| thread::sleep(Duration::from_millis(1)));
11 queue.enqueue(|| thread::sleep(Duration::from_millis(50)));
12 queue.enqueue(|| thread::sleep(Duration::from_millis(1000)));
13 thread::sleep(Duration::from_millis(100));
14
15 println!(
16 "{}",
17 prometrics::default_gatherer()
18 .lock()
19 .unwrap()
20 .gather()
21 .to_text()
22 );
23}Sourcepub fn set_worker_count(&self, count: usize)
pub fn set_worker_count(&self, count: usize)
Updates the number of worker threads of this queue.
Sourcepub fn worker_count(&self) -> usize
pub fn worker_count(&self) -> usize
Returns the number of worker threads of this queue.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TaskQueue
impl RefUnwindSafe for TaskQueue
impl Send for TaskQueue
impl Sync for TaskQueue
impl Unpin for TaskQueue
impl UnwindSafe for TaskQueue
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