pub struct Scheduler { /* private fields */ }
Expand description
The Scheduler
container
Implementations§
Source§impl Scheduler
impl Scheduler
Sourcepub fn handle(&self) -> SchedulerHandle
pub fn handle(&self) -> SchedulerHandle
Get the SchedulerHandle
for this scheduler. Can be used to setup tasks that cancel themselves on some condition.
Sourcepub fn once<F>(f: F) -> Self
pub fn once<F>(f: F) -> Self
Create a scheduler to run a one-time job in a background thread
Examples found in repository?
examples/simple.rs (line 2)
1fn main() {
2 let _once_handle = scheduling::Scheduler::once(|| println!("ONCE")).start();
3
4 let recurring_handle = scheduling::Scheduler::delayed_recurring(
5 std::time::Duration::from_secs(1),
6 std::time::Duration::from_secs(1),
7 || println!("1 SEC ELAPSED"),
8 )
9 .start();
10
11 std::thread::sleep(std::time::Duration::from_secs(5));
12
13 recurring_handle.cancel();
14
15 std::thread::sleep(std::time::Duration::from_secs(5));
16}
Sourcepub fn delayed_once<F>(delay: Duration, f: F) -> Self
pub fn delayed_once<F>(delay: Duration, f: F) -> Self
Create a scheduler to run a one-time job with an initial delay
Sourcepub fn recurring<F>(rate: Duration, f: F) -> Self
pub fn recurring<F>(rate: Duration, f: F) -> Self
Create a scheduler to run a recurring job at a fixed rate
Sourcepub fn delayed_recurring<F>(delay: Duration, rate: Duration, f: F) -> Self
pub fn delayed_recurring<F>(delay: Duration, rate: Duration, f: F) -> Self
Create a scheduler to run a recurring job at a fixed rate, with an initial delay
Examples found in repository?
examples/simple.rs (lines 4-8)
1fn main() {
2 let _once_handle = scheduling::Scheduler::once(|| println!("ONCE")).start();
3
4 let recurring_handle = scheduling::Scheduler::delayed_recurring(
5 std::time::Duration::from_secs(1),
6 std::time::Duration::from_secs(1),
7 || println!("1 SEC ELAPSED"),
8 )
9 .start();
10
11 std::thread::sleep(std::time::Duration::from_secs(5));
12
13 recurring_handle.cancel();
14
15 std::thread::sleep(std::time::Duration::from_secs(5));
16}
Sourcepub fn start(self) -> SchedulerHandle
pub fn start(self) -> SchedulerHandle
Start running the Scheduler
and return its handle
Examples found in repository?
examples/simple.rs (line 2)
1fn main() {
2 let _once_handle = scheduling::Scheduler::once(|| println!("ONCE")).start();
3
4 let recurring_handle = scheduling::Scheduler::delayed_recurring(
5 std::time::Duration::from_secs(1),
6 std::time::Duration::from_secs(1),
7 || println!("1 SEC ELAPSED"),
8 )
9 .start();
10
11 std::thread::sleep(std::time::Duration::from_secs(5));
12
13 recurring_handle.cancel();
14
15 std::thread::sleep(std::time::Duration::from_secs(5));
16}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Scheduler
impl !RefUnwindSafe for Scheduler
impl Send for Scheduler
impl !Sync for Scheduler
impl Unpin for Scheduler
impl !UnwindSafe for Scheduler
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