Skip to main content

DispatcherTimer

Struct DispatcherTimer 

Source
pub struct DispatcherTimer { /* private fields */ }
Expand description

A timer that is integrated into the Dispatcher queues, and will be processed after a given amount of time at a specified priority.

Timers belong to the thread of their dispatcher: they are created, started and stopped there, and that is where tick handlers run. To start a timer from another thread, post a job that creates it.

Implementations§

Source§

impl DispatcherTimer

Source

pub fn new() -> Rc<DispatcherTimer>

Creates a timer that uses the current thread’s dispatcher to process the timer event at background priority.

Source

pub fn with_priority(priority: DispatcherPriority) -> Rc<DispatcherTimer>

Creates a timer that uses the current thread’s dispatcher to process the timer event at the specified priority.

Source

pub fn with_priority_and_dispatcher( priority: DispatcherPriority, dispatcher: &Arc<Dispatcher>, ) -> Rc<DispatcherTimer>

Creates a timer that uses the specified dispatcher to process the timer event at the specified priority.

Source

pub fn with_interval( interval: Duration, priority: DispatcherPriority, dispatcher: &Arc<Dispatcher>, ) -> Rc<DispatcherTimer>

Creates a timer that uses the specified dispatcher to process the timer event at the specified priority after the specified interval.

§Panics

Panics when the priority is invalid or inactive, when the interval is longer than i32::MAX milliseconds and when called from a thread other than the dispatcher’s.

Source

pub fn with_callback( interval: Duration, priority: DispatcherPriority, callback: impl Fn(&DispatcherTimer) + 'static, ) -> Rc<DispatcherTimer>

Creates a timer that is bound to the current thread’s dispatcher and will be processed after the specified interval, at the specified priority, calling the specified handler. The timer is started.

Source

pub fn with_callback_and_dispatcher( interval: Duration, priority: DispatcherPriority, dispatcher: &Arc<Dispatcher>, callback: impl Fn(&DispatcherTimer) + 'static, ) -> Rc<DispatcherTimer>

Creates a timer that is bound to the specified dispatcher and will be processed after the specified interval, at the specified priority, calling the specified handler. The timer is started.

Source

pub fn dispatcher(&self) -> &Arc<Dispatcher> ⓘ

Gets the dispatcher this timer is associated with.

Source

pub fn is_enabled(&self) -> bool

Gets whether the timer is running.

Source

pub fn set_is_enabled(&self, value: bool)

Starts or stops the timer.

Source

pub fn interval(&self) -> Duration

Gets the time between timer ticks.

Source

pub fn set_interval(&self, value: Duration)

Sets the time between timer ticks.

Source

pub fn start(&self)

Starts the timer.

Source

pub fn stop(&self)

Stops the timer.

Source

pub fn run( action: impl Fn() -> bool + 'static, interval: Duration, priority: DispatcherPriority, ) -> Rc<dyn IDisposable>

Starts a new timer.

action is called on each tick; the timer stops when it returns false. Disposing the returned value stops the timer.

Source

pub fn run_once( action: impl Fn() + 'static, interval: Duration, priority: DispatcherPriority, ) -> Rc<dyn IDisposable>

Runs a method once, after the specified interval.

Disposing the returned value cancels the timer.

Source

pub fn tick( &self, handler: impl Fn(&DispatcherTimer) + 'static, ) -> Rc<dyn IDisposable>

Occurs when the specified timer interval has elapsed and the timer is enabled.

Source

pub fn tag(&self) -> Option<BoxedValue>

Any data that the caller wants to pass along with the timer.

Source

pub fn set_tag(&self, value: Option<BoxedValue>)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.