Struct job_scheduler_ng::JobScheduler

source ·
pub struct JobScheduler<'a> { /* private fields */ }
Expand description

The JobScheduler contains and executes the scheduled jobs.

Implementations§

source§

impl<'a> JobScheduler<'a>

source

pub const fn new() -> Self

Create a new JobScheduler.

source

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

Add a job to the JobScheduler

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

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

Remove a job from the JobScheduler

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);
source

pub fn tick(&mut self)

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.

loop {
    sched.tick();
    std::thread::sleep(Duration::from_millis(500));
}
source

pub fn time_till_next_job(&self) -> Duration

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

loop {
    sched.tick();
    std::thread::sleep(sched.time_till_next_job());
}

Trait Implementations§

source§

impl<'a> Default for JobScheduler<'a>

source§

fn default() -> JobScheduler<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for JobScheduler<'a>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.