pub struct Timer { /* private fields */ }
Expand description
The main structure of this library, a Timer
handles scheduling one-off and repeating tasks,
which are executed on a background thread. Tasks should be short-lived (as they block the
thread) synchronous functions.
Implementations§
Source§impl Timer
impl Timer
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new Timer. This will immediately start a background thread for executing tasks, which will be shut down on drop.
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Construct a new Timer with underlying capacity for the given number of tasks as a microoptimization. This will immediately start a background thread for executing tasks, which will be shut down on drop.
Sourcepub fn schedule_in<F: FnOnce() + UnwindSafe + Send + 'static>(
&mut self,
duration: Duration,
f: F,
) -> TaskGuard
pub fn schedule_in<F: FnOnce() + UnwindSafe + Send + 'static>( &mut self, duration: Duration, f: F, ) -> TaskGuard
Schedule a task to run once, after the given duration
Sourcepub fn schedule_at<F: FnOnce() + UnwindSafe + Send + 'static>(
&mut self,
system_time: SystemTime,
f: F,
) -> TaskGuard
pub fn schedule_at<F: FnOnce() + UnwindSafe + Send + 'static>( &mut self, system_time: SystemTime, f: F, ) -> TaskGuard
Schedule a task to run at a given wall-clock time. This will be converted to an Instant and run according to the monotonic clock, so may have… somewhat unpredictable behavior around leap seconds.
Sourcepub fn schedule_repeating<F: FnMut() + UnwindSafe + Send + 'static>(
&mut self,
interval: Duration,
f: F,
) -> TaskGuard
pub fn schedule_repeating<F: FnMut() + UnwindSafe + Send + 'static>( &mut self, interval: Duration, f: F, ) -> TaskGuard
Schedule a task to run periodically, after every interval
Sourcepub fn schedule_immediately<F: FnOnce() + UnwindSafe + Send + 'static>(
&mut self,
f: F,
)
pub fn schedule_immediately<F: FnOnce() + UnwindSafe + Send + 'static>( &mut self, f: F, )
Schedule a task to run as soon as possible