Struct tasklet::TaskScheduler

source ·
pub struct TaskScheduler<T>
where T: TimeZone + Clone + Send + 'static,
{ /* private fields */ }
Expand description

Task scheduler and executor.

Implementations§

source§

impl<T> TaskScheduler<T>
where T: TimeZone + Clone + Send + 'static,

TaskScheduler implementation.

source

pub fn default(timezone: T) -> TaskScheduler<T>

Create a new instance of TaskSchedule with default sleep and no tasks to execute.

§Arguments
  • timezone - the scheduler’s timezone.
§Examples
let _ = TaskScheduler::default(chrono::Utc);
source

pub fn new(sleep: usize, timezone: T) -> TaskScheduler<T>

Create a new instance of TaskScheduler with no tasks to execute.

§Arguments
  • sleep - The execution frequency (in ms).
  • timezone - The scheduler’s timezone.
§Examples
// Create a new `TaskScheduler` instance that executes every 1000ms.
let _ = TaskScheduler::new(1000, chrono::Local);
source

pub fn set_task_gen( &mut self, task_gen: TaskGenerator<T> ) -> &mut TaskScheduler<T>

Set a TaskGenerator instance for the TaskScheduler.

§Arguments
  • task_gen - a TaskGenerator instance.
§Examples
// Create a new `TaskScheduler` instance and attach an `TaskGenerator` to it.
let mut scheduler = TaskScheduler::default(chrono::Local);
let mut generator = TaskGenerator::new("1 * * * * * *", chrono::Local, || None);
scheduler.set_task_gen(generator);
source

pub fn add_task(&mut self, task: Task<T>) -> &mut TaskScheduler<T>

Add a new task in the execution queue.

§Arguments
  • task - a Task instance.
§Examples
// Create a new `TaskScheduler` and attach a task to it.
let mut scheduler = TaskScheduler::default(chrono::Local);
// Add a task that executes every second forever.
scheduler.add_task(Task::new("* * * * * * *", None, None, chrono::Local));
source

pub async fn run(&mut self)

Main execution loop.

Executes the main flow of the scheduler. At first initialize all the tasks and then run the execution loop.

If there is a task generation/discovery method provided, executed on every loop.

Auto Trait Implementations§

§

impl<T> Freeze for TaskScheduler<T>
where T: Freeze, <T as TimeZone>::Offset: Freeze,

§

impl<T> !RefUnwindSafe for TaskScheduler<T>

§

impl<T> !Send for TaskScheduler<T>

§

impl<T> !Sync for TaskScheduler<T>

§

impl<T> Unpin for TaskScheduler<T>
where T: Unpin, <T as TimeZone>::Offset: Unpin,

§

impl<T> !UnwindSafe for TaskScheduler<T>

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.