pub struct Task {
pub pool: Vec<UnboundedSender<AsyncTask>>,
pub counter: Arc<AtomicUsize>,
pub shutdown: Arc<AtomicBool>,
pub notifies: Vec<Arc<Notify>>,
}Expand description
Task manager for handling async tasks across worker threads.
This structure manages a pool of task senders distributed across multiple worker threads, enabling efficient round-robin task scheduling with event-driven wake-up mechanism.
Fields§
§pool: Vec<UnboundedSender<AsyncTask>>Pool of unbounded senders for distributing tasks to worker threads.
counter: Arc<AtomicUsize>Atomic counter for round-robin task distribution across workers.
shutdown: Arc<AtomicBool>Flag indicating whether the task pool should shut down.
notifies: Vec<Arc<Notify>>Notification handles for precise wake-up of specific workers.
Implementations§
Source§impl Task
impl Task
Sourcepub fn try_spawn_local<F>(&self, index_opt: Option<usize>, hook: F) -> bool
pub fn try_spawn_local<F>(&self, index_opt: Option<usize>, hook: F) -> bool
Attempts to spawn a server task onto the global server task pool.
This function sends the task to one of the worker threads in the pool. The worker is selected using a round-robin algorithm based on an atomic counter, or a forced index if provided.
§Arguments
Option<usize>: An optional index to force selection of a specific worker. If None, the worker is selected using round-robin distribution.Future<Output = ()> + Send + 'static: The future to spawn on the task pool.
§Returns
bool: true if the task was successfully sent, false otherwise.
Source§impl Task
impl Task
pub fn get_pool(&self) -> &Vec<UnboundedSender<AsyncTask>>
pub fn get_mut_pool(&mut self) -> &mut Vec<UnboundedSender<AsyncTask>>
pub fn set_pool(&mut self, val: Vec<UnboundedSender<AsyncTask>>) -> &mut Self
pub fn get_counter(&self) -> &Arc<AtomicUsize> ⓘ
pub fn get_mut_counter(&mut self) -> &mut Arc<AtomicUsize> ⓘ
pub fn set_counter(&mut self, val: Arc<AtomicUsize>) -> &mut Self
pub fn get_shutdown(&self) -> &Arc<AtomicBool> ⓘ
pub fn get_mut_shutdown(&mut self) -> &mut Arc<AtomicBool> ⓘ
pub fn set_shutdown(&mut self, val: Arc<AtomicBool>) -> &mut Self
pub fn get_notifies(&self) -> &Vec<Arc<Notify>>
pub fn get_mut_notifies(&mut self) -> &mut Vec<Arc<Notify>>
pub fn set_notifies(&mut self, val: Vec<Arc<Notify>>) -> &mut Self
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Task
impl RefUnwindSafe for Task
impl Send for Task
impl Sync for Task
impl Unpin for Task
impl UnsafeUnpin for Task
impl UnwindSafe for Task
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