pub struct WorkerPool<'threads, T>{ /* private fields */ }
Expand description
A pool of OS threads:
- 1 aggregator thread reading from
main_tasks_rx
(single consumer), - N worker threads, each with its own private channel,
- A results channel for
TaskResult
.
Implementations§
Source§impl<'threads, T> WorkerPool<'threads, T>
impl<'threads, T> WorkerPool<'threads, T>
Sourcepub fn new_in_scope(
scope: &'threads Scope<'threads, '_>,
num_workers: usize,
buffer_size: usize,
) -> Self
pub fn new_in_scope( scope: &'threads Scope<'threads, '_>, num_workers: usize, buffer_size: usize, ) -> Self
Build the aggregator + N workers within a synchronous scope.
- The aggregator (thread) reads from
main_tasks_rx
(single consumer). - It fans out tasks to each worker’s private channel in round-robin.
- Each worker runs in a separate OS thread, with its own mini tokio runtime.
- We also have one results channel so the aggregator can send back TaskResult items,
which an external consumer (like
process_immediate
) can poll viatry_recv_result
.
The aggregator closes each worker’s channel at the end, ensuring that idle workers (which never receive tasks) also exit cleanly.
Sourcepub async fn submit(
&self,
item: TaskItem<'threads, T>,
) -> Result<(), NetworkError>
pub async fn submit( &self, item: TaskItem<'threads, T>, ) -> Result<(), NetworkError>
Submit a task => aggregator picks it up, fans out to a worker.
Sourcepub async fn try_recv_result(&self) -> Option<TaskResult>
pub async fn try_recv_result(&self) -> Option<TaskResult>
Non-blocking poll of the results channel from workers
pub fn is_main_channel_closed(&self) -> bool
Sourcepub fn close_main_tasks_channel(&self)
pub fn close_main_tasks_channel(&self)
Force aggregator to see “None” => aggregator returns => shuts down
Auto Trait Implementations§
impl<'threads, T> !Freeze for WorkerPool<'threads, T>
impl<'threads, T> !RefUnwindSafe for WorkerPool<'threads, T>
impl<'threads, T> Send for WorkerPool<'threads, T>
impl<'threads, T> Sync for WorkerPool<'threads, T>
impl<'threads, T> Unpin for WorkerPool<'threads, T>
impl<'threads, T> !UnwindSafe for WorkerPool<'threads, T>
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