DispatcherTimer
struct · ferroui-base · v0.5.0
struct DispatcherTimer
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.
Members
newwith_prioritywith_priority_and_dispatcherwith_intervalwith_callbackwith_callback_and_dispatcherdispatcheris_enabledset_is_enabledintervalset_intervalstartstoprunrun_onceticktagset_tag
new
fn new() -> Rc<DispatcherTimer>
Creates a timer that uses the current thread's dispatcher to process the timer event at background priority.
with_priority
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.
with_priority_and_dispatcher
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.
with_interval
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.
with_callback
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.
with_callback_and_dispatcher
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.
dispatcher
fn dispatcher(self: &Self) -> &Arc<Dispatcher>
Gets the dispatcher this timer is associated with.
is_enabled
fn is_enabled(self: &Self) -> bool
Gets whether the timer is running.
set_is_enabled
fn set_is_enabled(self: &Self, value: bool)
Starts or stops the timer.
interval
fn interval(self: &Self) -> Duration
Gets the time between timer ticks.
set_interval
fn set_interval(self: &Self, value: Duration)
Sets the time between timer ticks.
start
fn start(self: &Self)
Starts the timer.
stop
fn stop(self: &Self)
Stops the timer.
run
fn run(action: impl Fn() -> bool + 'static, interval: Duration, priority: DispatcherPriority) -> Subscription
Starts a new timer.
action is called on each tick; the timer stops when it returns
false. Dropping the returned guard (or calling
Subscription::dispose) stops the timer; Subscription::detach
keeps it running for the life of the timer.
run_once
fn run_once(action: impl Fn() -> () + 'static, interval: Duration, priority: DispatcherPriority) -> Subscription
Runs a method once, after the specified interval.
Dropping the returned guard (or calling Subscription::dispose)
cancels the timer; Subscription::detach keeps it until its only
tick.
tick
fn tick(self: &Self, handler: impl Fn(&DispatcherTimer) -> () + 'static) -> Rc<dyn IDisposable>
Occurs when the specified timer interval has elapsed and the timer is enabled.
tag
fn tag(self: &Self) -> Option<BoxedValue>
Any data that the caller wants to pass along with the timer.
set_tag
fn set_tag(self: &Self, value: Option<BoxedValue>)
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeClassDefaultsBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyErasedDestructorIntoEither
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.