pub struct WorkerPool<D, S>where
S: WorkerTemplate,{ /* private fields */ }Expand description
WorkerPool manages a pool of worker threads for parallel task execution.
It allows spawning workers, sending data to them, and managing their lifecycle.
Implementations§
Source§impl<D: Send + 'static, S: WorkerTemplate> WorkerPool<D, S>
impl<D: Send + 'static, S: WorkerTemplate> WorkerPool<D, S>
Sourcepub fn new(len: u64, template: S, draw_hz: u8) -> Self
pub fn new(len: u64, template: S, draw_hz: u8) -> Self
Creates a new WorkerPool with a specified number of workers, a worker template, and a draw frequency.
§Arguments
len- The number of workers in the pool.template- The template for creating progress bars for each worker.draw_hz- The frequency at which the progress bars are drawn (frames per second).
Sourcepub fn new_task_id(&self) -> Uid
pub fn new_task_id(&self) -> Uid
Generates a new unique task ID.
Sourcepub fn spawn_worker<F, Fut>(&mut self, f: F) -> Uid
pub fn spawn_worker<F, Fut>(&mut self, f: F) -> Uid
Spawns a new worker in the pool.
§Arguments
f- A closure that represents the worker’s task. It takes dataDand aMainProgressinstance as input and returns aResult.
Sourcepub fn main_ui(&self) -> MainProgress<S>
pub fn main_ui(&self) -> MainProgress<S>
Returns a clone of the main progress instance.
Sourcepub async fn sigint(&mut self)
pub async fn sigint(&mut self)
Handles the SIGINT signal, setting a prefix message and stopping all workers.
Sourcepub async fn send_seqcst(&mut self, data: D) -> Result<(), D>
pub async fn send_seqcst(&mut self, data: D) -> Result<(), D>
Sends data to the first available worker in the pool.
§Arguments
data: The data to send to the worker.
Returns: Result<(), D>
Sourcepub fn thead_count(&self) -> usize
pub fn thead_count(&self) -> usize
Returns the number of active threads in the pool.
Source§impl<D: Send, S: WorkerTemplate> WorkerPool<D, S>
impl<D: Send, S: WorkerTemplate> WorkerPool<D, S>
Sourcepub fn get_style(template: impl AsRef<str>) -> ProgressStyle
pub fn get_style(template: impl AsRef<str>) -> ProgressStyle
Retrieves a ProgressStyle based on the provided template.
This style includes customized progress characters, date formatting, and status indicators.
Sourcepub fn eprintln(&self, line: impl AsRef<str>) -> Result<(), Error>
pub fn eprintln(&self, line: impl AsRef<str>) -> Result<(), Error>
Prints an error line to the UI.
Sourcepub fn horizontal_line(len: usize) -> String
pub fn horizontal_line(len: usize) -> String
Generates a horizontal line of a specified length.
Sourcepub fn vertical_line(len: usize) -> String
pub fn vertical_line(len: usize) -> String
Generates a vertical line of a specified length.