Task scheduler in code that runs a function at specific intervals,
Example
usetask_schedule::{schedule_tasks,ScheduledTask};usetask_schedule::utils::*;fntask_without_params(){println!("I am running sec task.");}fntask_min(){println!("I am running min task.");}fntask_hours(){println!("I am running hours task.");}fntask_days(){println!("I am running days task.");}fntask_week(){println!("I am running week task.");}fntask_with_params(a:i32,b:&str){println!("Task with parameters: a = {}, b = {}",a,b);}fntask_with_params_wrapper(){task_with_params(42,"Hello");}fnmain(){letmuttasks=vec![ScheduledTask::new(convert_duration_to_seconds(1),task_without_paramsasfn()),ScheduledTask::new(convert_duration_to_seconds(2),task_with_params_wrapperasfn()),ScheduledTask::new(convert_duration_to_minutes(1),task_minasfn()),ScheduledTask::new(convert_duration_to_hours(1),task_hoursasfn()),ScheduledTask::new(convert_duration_to_days(1),task_daysasfn()),ScheduledTask::new(convert_duration_to_weeks(1),task_weekasfn()),];schedule_tasks(&muttasks);}
Output
I am running sec task.
Task with parameters: a = 42, b = Hello
I am running sec task.
I am running sec task.
Task with parameters: a = 42, b = Hello
I am running sec task.
I am running sec task.
Task with parameters: a = 42, b = Hello
I am running sec task.
I am running sec task.
Task with parameters: a = 42, b = Hello
I am running sec task.
I am running sec task.
Task with parameters: a = 42, b = Hello
I am running sec task.
I am running sec task.
Task with parameters: a = 42, b = Hello
I am running sec task.
I am running sec task.
Task with parameters: a = 42, b = Hello
I am running sec task.
I am running sec task.
Task with parameters: a = 42, b = Hello
I am running sec task.
I am running sec task.
Top comments (0)