pub struct Schedule { /* private fields */ }
Expand description
A scheduler to run tasks.
This is not a precise scheduler; tasks may run later than scheduled.
Implementations§
Source§impl Schedule
impl Schedule
Sourcepub fn builder() -> ScheduleBuilder
pub fn builder() -> ScheduleBuilder
Examples found in repository?
examples/schedule.rs (line 25)
9fn main() {
10 let periodic_task = ScheduledTask::new(
11 ScheduleAt::Interval(Duration::seconds(4)),
12 task!(async { println!("You'll see me every four seconds") })
13 ).unwrap();
14
15 let onetime_task = ScheduledTask::new(
16 ScheduleAt::DateTime(Utc::now() + Duration::seconds(15)),
17 task!(task2())
18 ).unwrap();
19
20 let daily_task = ScheduledTask::new(
21 ScheduleAt::Daily(Time::from_hms(01, 23, 45)),
22 task!(async { println!("Hello"); })
23 ).unwrap();
24
25 let schedule = Schedule::builder()
26 .tasks([
27 periodic_task,
28 onetime_task,
29 daily_task,
30 ])
31 .wake_interval(Duration::seconds(1)).unwrap()
32 .build();
33
34 schedule.run();
35
36 // run() exits immediately, so we need to wait a bit.
37 std::thread::sleep(Duration::seconds(30).to_std().unwrap());
38}
Sourcepub fn run(self)
pub fn run(self)
Run the scheduled tasks at their configured times.
Examples found in repository?
examples/schedule.rs (line 34)
9fn main() {
10 let periodic_task = ScheduledTask::new(
11 ScheduleAt::Interval(Duration::seconds(4)),
12 task!(async { println!("You'll see me every four seconds") })
13 ).unwrap();
14
15 let onetime_task = ScheduledTask::new(
16 ScheduleAt::DateTime(Utc::now() + Duration::seconds(15)),
17 task!(task2())
18 ).unwrap();
19
20 let daily_task = ScheduledTask::new(
21 ScheduleAt::Daily(Time::from_hms(01, 23, 45)),
22 task!(async { println!("Hello"); })
23 ).unwrap();
24
25 let schedule = Schedule::builder()
26 .tasks([
27 periodic_task,
28 onetime_task,
29 daily_task,
30 ])
31 .wake_interval(Duration::seconds(1)).unwrap()
32 .build();
33
34 schedule.run();
35
36 // run() exits immediately, so we need to wait a bit.
37 std::thread::sleep(Duration::seconds(30).to_std().unwrap());
38}
Auto Trait Implementations§
impl Freeze for Schedule
impl !RefUnwindSafe for Schedule
impl Send for Schedule
impl !Sync for Schedule
impl Unpin for Schedule
impl !UnwindSafe for Schedule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more