pub struct Worker {
Context: Context<Task>,
IsRunning: Arc<AtomicBool>,
}Expand description
Represents a worker that executes tasks from its assigned Context.
Fields§
§Context: Context<Task>The worker’s execution context, which contains its private deques and a reference to the shared queue system.
IsRunning: Arc<AtomicBool>An atomic flag, shared by all workers, to signal a shutdown request.
Implementations§
Source§impl Worker
impl Worker
Sourcepub fn Create(Context: Context<Task>, IsRunning: Arc<AtomicBool>) -> Self
pub fn Create(Context: Context<Task>, IsRunning: Arc<AtomicBool>) -> Self
Creates a new Worker with its unique execution context and a reference
to the scheduler’s running state.
Sourcepub async fn Run(self)
pub async fn Run(self)
The main execution loop for the worker.
This loop continuously tries to find and execute tasks. It prioritizes its local queue and, if empty, attempts to steal work from other workers or the global queue. If no work is found anywhere, it yields briefly to avoid busy-waiting.
Sourcefn PopLocal(&self) -> Option<Task>
fn PopLocal(&self) -> Option<Task>
Attempts to pop a single task from the local deques, honoring priority from high to low.
Sourcefn StealFromSystem(&self) -> Option<Task>
fn StealFromSystem(&self) -> Option<Task>
Attempts to steal a batch of work from the system.
It steals from the highest-priority queue that has work, populating its own local queue and returning the first task immediately for execution.