# DispatcherTimer

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/threading/struct-dispatchertimer/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct DispatcherTimer
```

A timer that is integrated into the [`Dispatcher`](/docs/0.5.0/api/ferroui-base/threading/struct-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.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L21)

## Members

- [`new`](#function-new)
- [`with_priority`](#function-with_priority)
- [`with_priority_and_dispatcher`](#function-with_priority_and_dispatcher)
- [`with_interval`](#function-with_interval)
- [`with_callback`](#function-with_callback)
- [`with_callback_and_dispatcher`](#function-with_callback_and_dispatcher)
- [`dispatcher`](#function-dispatcher)
- [`is_enabled`](#function-is_enabled)
- [`set_is_enabled`](#function-set_is_enabled)
- [`interval`](#function-interval)
- [`set_interval`](#function-set_interval)
- [`start`](#function-start)
- [`stop`](#function-stop)
- [`run`](#function-run)
- [`run_once`](#function-run_once)
- [`tick`](#function-tick)
- [`tag`](#function-tag)
- [`set_tag`](#function-set_tag)

<a id="function-new"></a>

### new

```rust
fn new() -> Rc<DispatcherTimer>
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L43)

<a id="function-with_priority"></a>

### with_priority

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L49)

<a id="function-with_priority_and_dispatcher"></a>

### with_priority_and_dispatcher

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L55)

<a id="function-with_interval"></a>

### with_interval

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L69)

<a id="function-with_callback"></a>

### with_callback

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L101)

<a id="function-with_callback_and_dispatcher"></a>

### with_callback_and_dispatcher

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L112)

<a id="function-dispatcher"></a>

### dispatcher

```rust
fn dispatcher(self: &Self) -> &Arc<Dispatcher>
```

Gets the dispatcher this timer is associated with.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L125)

<a id="function-is_enabled"></a>

### is_enabled

```rust
fn is_enabled(self: &Self) -> bool
```

Gets whether the timer is running.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L130)

<a id="function-set_is_enabled"></a>

### set_is_enabled

```rust
fn set_is_enabled(self: &Self, value: bool)
```

Starts or stops the timer.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L135)

<a id="function-interval"></a>

### interval

```rust
fn interval(self: &Self) -> Duration
```

Gets the time between timer ticks.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L144)

<a id="function-set_interval"></a>

### set_interval

```rust
fn set_interval(self: &Self, value: Duration)
```

Sets the time between timer ticks.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L149)

<a id="function-start"></a>

### start

```rust
fn start(self: &Self)
```

Starts the timer.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L166)

<a id="function-stop"></a>

### stop

```rust
fn stop(self: &Self)
```

Stops the timer.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L177)

<a id="function-run"></a>

### run

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L204)

<a id="function-run_once"></a>

### run_once

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L224)

<a id="function-tick"></a>

### tick

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L243)

<a id="function-tag"></a>

### tag

```rust
fn tag(self: &Self) -> Option<BoxedValue>
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L254)

<a id="function-set_tag"></a>

### set_tag

```rust
fn set_tag(self: &Self, value: Option<BoxedValue>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/threading/dispatcher_timer.rs#L258)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
