[][src]Struct job_scheduler::JobScheduler

pub struct JobScheduler<'a> { /* fields omitted */ }

The JobScheduler contains and executes the scheduled jobs.

Methods

impl<'a> JobScheduler<'a>[src]

pub fn new() -> JobScheduler<'a>[src]

Create a new JobScheduler.

pub fn add(&mut self, job: Job<'a>) -> Uuid[src]

Add a job to the JobScheduler

This example is not tested
let mut sched = JobScheduler::new();
sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || {
    println!("I get executed every 10 seconds!");
}));

pub fn remove(&mut self, job_id: Uuid) -> bool[src]

Remove a job from the JobScheduler

This example is not tested
let mut sched = JobScheduler::new();
let job_id = sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || {
    println!("I get executed every 10 seconds!");
}));
sched.remove(job_id);

pub fn tick(&mut self)[src]

The tick method increments time for the JobScheduler and executes any pending jobs. It is recommended to sleep for at least 500 milliseconds between invocations of this method.

This example is not tested
loop {
    sched.tick();
    std::thread::sleep(Duration::from_millis(500));
}

pub fn time_till_next_job(&self) -> Duration[src]

The time_till_next_job method returns the duration till the next job is supposed to run. This can be used to sleep until then without waking up at a fixed interval.AsMut

This example is not tested
loop {
    sched.tick();
    std::thread::sleep(sched.time_till_next_job());
}

Trait Implementations

impl<'a> Default for JobScheduler<'a>[src]

Auto Trait Implementations

impl<'a> !RefUnwindSafe for JobScheduler<'a>

impl<'a> !Send for JobScheduler<'a>

impl<'a> !Sync for JobScheduler<'a>

impl<'a> Unpin for JobScheduler<'a>

impl<'a> !UnwindSafe for JobScheduler<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,