[−][src]Struct hjul::Timer
Methods
impl Timer
[src]
pub fn stop(&self)
[src]
Stop the timer (preventing execution of the callback in the future)
Note
Another way to stop a timer is to drop every clone of the timer.
Example
let timer = runner.timer(|| assert!(false)); timer.reset(Duration::from_millis(200)); timer.stop(); // callback is never executed thread::sleep(Duration::from_millis(500));
pub fn reset(&self, duration: Duration)
[src]
Restart the timer, regardless of whether the timer is running or not. e.g. repeatably calling .reset(1 sec) will cause the timer to never fire.
Arguments
duration
: duration until the callback should execute
Example
let timer = runner.timer(|| assert!(false)); // the timer never fires let dur = Duration::from_millis(200); for _ in 0..5 { timer.reset(dur); thread::sleep(dur / 2); } // timer is dropped and cancelled
pub fn start(&self, duration: Duration) -> bool
[src]
Start the timer, but only if the timer is not already pending e.g. if repeatably calling .start(1 sec), the timer will fire ~ once every second
Arguments
duration
: duration until the callback should execute
Returns
A bool indicating whether the timer was started (true) or already running (false).
Example
let timer = runner.timer(|| println!("fired")); // this timer will fire twice let dur = Duration::from_millis(200); for _ in 0..5 { timer.start(dur); thread::sleep(dur / 2); } // timer is dropped and cancelled
pub fn fire(&self)
[src]
Manually cause the timer to fire immediately. This cancels any pending timeout (equivalent to calling .stop()) before executing the callback.
Note
The callback is run in the calling thread
as oppose to being run by the thread in the associated Runner
instance.
Example
let timer = runner.timer(|| println!("fired")); timer.start(Duration::from_millis(200)); timer.fire(); // timer is fired immediately, not after 200ms.
Trait Implementations
Auto Trait Implementations
impl Send for Timer
impl Unpin for Timer
impl Sync for Timer
impl !UnwindSafe for Timer
impl !RefUnwindSafe for Timer
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,