Struct sixtyfps::Timer [−]
pub struct Timer { /* fields omitted */ }
Expand description
Timer is a handle to the timer system that allows triggering a callback to be called after a specified period of time.
Implementations
impl Timer
impl Timer
Starts the timer with the given mode and duration, in order for the callback to called when the timer fires. If the timer has been started previously and not fired yet, then it will be restarted.
Arguments:
mode
: The timer mode to apply, i.e. whether to repeatedly fire the timer or just once.duration
: The duration from now until when the timer should fire.callback
: The function to call when the time has been reached or exceeded.
pub fn single_shot(duration: Duration, callback: impl FnOnce() + 'static)
pub fn single_shot(duration: Duration, callback: impl FnOnce() + 'static)
Starts the timer with the duration, in order for the callback to called when the timer fires. It is fired only once and then deleted.
Arguments:
duration
: The duration from now until when the timer should fire.callback
: The function to call when the time has been reached or exceeded.
pub fn stop(&self)
pub fn stop(&self)
Stops the previously started timer. Does nothing if the timer has never been started. A stopped timer cannot be restarted with restart() – instead you need to call start().
pub fn restart(&self)
pub fn restart(&self)
Restarts the timer, if it was previously started.