Scheduler

Trait Scheduler 

Source
pub trait Scheduler: Send + Sync {
    // Required methods
    fn every(&self, interval: Duration, task: BoxedTask) -> Result<TaskHandle>;
    fn once(&self, task: BoxedOnceTask) -> Result<()>;
    fn cancel(&self, handle: TaskHandle) -> Result<()>;
}

Required Methods§

Source

fn every(&self, interval: Duration, task: BoxedTask) -> Result<TaskHandle>

Schedule a task to run at fixed intervals

The task will be scheduled to run every interval duration. The next execution time is calculated when the task is picked up for execution (not when it completes). This means if a task takes longer than its interval, multiple instances may be queued.

Source

fn once(&self, task: BoxedOnceTask) -> Result<()>

Submit a one-time task for immediate execution with FnOnce semantics

The task will be queued for execution based on its priority and consumed on execution. This allows tasks to move captured values without requiring Arc/Mutex wrappers. This method returns immediately without waiting for execution.

§Arguments
  • task - The one-time task to execute
§Returns

Ok(()) if task was successfully queued, Err if queue is full or worker pool is shut down

Source

fn cancel(&self, handle: TaskHandle) -> Result<()>

Cancel a scheduled task

Implementors§