Skip to main content

http_type/task/
struct.rs

1use crate::*;
2
3/// Task manager for handling async tasks across worker threads.
4///
5/// This structure manages a pool of task senders distributed across
6/// multiple worker threads, enabling efficient round-robin task scheduling
7/// with event-driven wake-up mechanism.
8#[derive(Clone, CustomDebug, Data, DisplayDebug)]
9pub struct Task {
10    /// Pool of unbounded senders for distributing tasks to worker threads.
11    #[get(pub(super))]
12    #[get_mut(pub(super))]
13    #[set(pub(super))]
14    pub(super) pool: Vec<UnboundedSender<AsyncTask>>,
15    /// Atomic counter for round-robin task distribution across workers.
16    #[get(pub(super))]
17    #[get_mut(pub(super))]
18    #[set(pub(super))]
19    pub(super) counter: Arc<AtomicUsize>,
20    /// Flag indicating whether the task pool should shut down.
21    #[get(pub(super))]
22    #[get_mut(pub(super))]
23    #[set(pub(super))]
24    pub(super) shutdown: Arc<AtomicBool>,
25    /// Notification handles for precise wake-up of specific workers.
26    #[get(pub(super))]
27    #[get_mut(pub(super))]
28    #[set(pub(super))]
29    pub(super) notifies: Vec<Arc<Notify>>,
30}