pub struct Task { /* private fields */ }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.
Implementations§
Source§impl Task
Inherent implementation of Task.
impl Task
Inherent implementation of 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.F- The future to spawn on the task pool, which requires theFuture<Output = ()> + Send + 'staticbound.
§Returns
bool- true if the task was successfully sent, false otherwise.
Source§impl Task
impl Task
pub fn get_pool( &self, ) -> &Vec<UnboundedSender<Pin<Box<dyn Future<Output = ()> + Send>>>>
pub fn get_mut_pool( &mut self, ) -> &mut Vec<UnboundedSender<Pin<Box<dyn Future<Output = ()> + Send>>>>
pub fn set_pool( &mut self, val: Vec<UnboundedSender<Pin<Box<dyn Future<Output = ()> + Send>>>>, ) -> &mut Task
pub fn get_counter(&self) -> &Arc<Atomic<usize>> ⓘ
pub fn get_mut_counter(&mut self) -> &mut Arc<Atomic<usize>> ⓘ
pub fn set_counter(&mut self, val: Arc<Atomic<usize>>) -> &mut Task
pub fn get_shutdown(&self) -> &Arc<Atomic<bool>> ⓘ
pub fn get_mut_shutdown(&mut self) -> &mut Arc<Atomic<bool>> ⓘ
pub fn set_shutdown(&mut self, val: Arc<Atomic<bool>>) -> &mut Task
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 Task
Trait Implementations§
Auto Trait Implementations§
impl Forget for Task
impl Freeze for Taskwhere
*const u8 is !null: Freeze,
PhantomData<UnboundedSender<Pin<Box<dyn Future<Output = ()> + Send>>>>: Freeze,
*const ArcInner<Atomic<usize>> is !null: Freeze,
PhantomData<ArcInner<Atomic<usize>>>: Freeze,
*const ArcInner<Atomic<bool>> is !null: Freeze,
PhantomData<ArcInner<Atomic<bool>>>: Freeze,
PhantomData<Arc<Notify>>: Freeze,
impl Move for Task
impl RefUnwindSafe for Taskwhere
Atomic<usize>: RefUnwindSafe,
Chan<Pin<Box<dyn Future<Output = ()> + Send>>, Semaphore>: RefUnwindSafe,
Atomic<bool>: RefUnwindSafe,
Notify: RefUnwindSafe,
impl Send for Task
impl Sync for Task
impl Unpin for Task
impl UnsafeUnpin for Taskwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<UnboundedSender<Pin<Box<dyn Future<Output = ()> + Send>>>>: UnsafeUnpin,
*const ArcInner<Atomic<usize>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<usize>>>: UnsafeUnpin,
*const ArcInner<Atomic<bool>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin,
PhantomData<Arc<Notify>>: UnsafeUnpin,
impl UnwindSafe for Taskwhere
RawVecInner: UnwindSafe,
Arc<Chan<Pin<Box<dyn Future<Output = ()> + Send>>, Semaphore>>: UnwindSafe,
Arc<Atomic<usize>>: UnwindSafe,
Arc<Atomic<bool>>: UnwindSafe,
Arc<Notify>: UnwindSafe,
Blanket Implementations§
impl<T> AnySend for T
impl<T> AnySendClone for T
impl<T> AnySendSync for T
impl<T> AnySendSyncClone for T
impl<T> AnySync for T
impl<T> AnySyncClone for T
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