# Dispatcher

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

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

```rust
struct Dispatcher
```

Provides services for managing work items on a thread.
## Threading

The object model is single-threaded and `Rc`-based; the dispatcher is the
one entry point that can be used from other threads. A dispatcher is
therefore handed out as `Arc<Dispatcher>` and is `Send + Sync`, and its
API is split in two:

* `post`, `invoke`,
  `invoke_async` and their variants can be called
  from **any thread**. Their callbacks (and results) must be `Send`.
* `post_local`, `invoke_local`,
  `invoke_async_local` and their variants
  accept callbacks that are not `Send` (they may capture `Rc`s, `Ref`s,
  ...). They can only be called **on the dispatcher thread**, which is
  checked at run time: calling them from another thread panics. The
  callback is kept in thread-local storage and never leaves the thread.

Timers ([`DispatcherTimer`](/docs/0.5.0/api/ferroui-base/threading/struct-dispatchertimer/)), the shutdown and unhandled-exception events
and everything else that takes non-`Send` handlers is likewise bound to
the dispatcher thread. So is the platform implementation
(`IDispatcherImpl`): other threads only ever use its
[`IDispatcherSignal`](/docs/0.5.0/api/ferroui-base/threading/trait-idispatchersignal/).
## Async

The dispatcher also runs futures, which takes the place of the
synchronization context of the reference implementation: it is a
schedule per priority of the executor of `ferroui-system`
(`task_schedule`).
`spawn_local`,
`spawn_local_with_priority` and
`spawn` run a future on the dispatcher thread, polling it
from jobs queued at a fixed priority, and give its
`ferroui_system::task::JoinHandle`; `start_local`
polls it for the first time inside the call. The deprecated
`invoke_async_task` and `DispatcherTaskScheduler` do the same and give a
`DispatcherTask`.
`resume`, `yield_now` and
`await_with_priority` change the priority at
which an `async` block continues. No async runtime is involved.
## Panics in callbacks

What the reference implementation does with exceptions is done here with
panics: a panic in a posted callback goes through
`unhandled_exception_filter` and
`unhandled_exception` and is re-raised on the
dispatcher thread unless a handler marks it as handled; a panic in an
`invoke`/`invoke_async` callback is captured and re-raised to whoever
waits for the operation. On targets that abort on panic none of this
applies.

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

## Members

- [`supports_run_loops`](#function-supports_run_loops)
- [`check_access`](#function-check_access)
- [`verify_access`](#function-verify_access)
- [`thread`](#function-thread)
- [`unhandled_exception`](#function-unhandled_exception)
- [`unhandled_exception_filter`](#function-unhandled_exception_filter)
- [`invoke`](#function-invoke)
- [`invoke_with_priority`](#function-invoke_with_priority)
- [`invoke_with_cancellation`](#function-invoke_with_cancellation)
- [`invoke_with_timeout`](#function-invoke_with_timeout)
- [`invoke_local`](#function-invoke_local)
- [`invoke_local_with_priority`](#function-invoke_local_with_priority)
- [`invoke_local_with_cancellation`](#function-invoke_local_with_cancellation)
- [`invoke_local_with_timeout`](#function-invoke_local_with_timeout)
- [`invoke_async`](#function-invoke_async)
- [`invoke_async_with_priority`](#function-invoke_async_with_priority)
- [`invoke_async_with_cancellation`](#function-invoke_async_with_cancellation)
- [`invoke_async_local`](#function-invoke_async_local)
- [`invoke_async_local_with_priority`](#function-invoke_async_local_with_priority)
- [`invoke_async_local_with_cancellation`](#function-invoke_async_local_with_cancellation)
- [`invoke_async_task`](#function-invoke_async_task)
- [`invoke_async_task_with_priority`](#function-invoke_async_task_with_priority)
- [`invoke_async_task_local`](#function-invoke_async_task_local)
- [`invoke_async_task_local_with_priority`](#function-invoke_async_task_local_with_priority)
- [`post`](#function-post)
- [`post_local`](#function-post_local)
- [`await_with_priority`](#function-await_with_priority)
- [`resume`](#function-resume)
- [`resume_with_priority`](#function-resume_with_priority)
- [`yield_now`](#function-yield_now)
- [`yield_with_priority`](#function-yield_with_priority)
- [`shutdown_started`](#function-shutdown_started)
- [`shutdown_finished`](#function-shutdown_finished)
- [`push_frame`](#function-push_frame)
- [`main_loop`](#function-main_loop)
- [`exit_all_frames`](#function-exit_all_frames)
- [`begin_invoke_shutdown`](#function-begin_invoke_shutdown)
- [`invoke_shutdown`](#function-invoke_shutdown)
- [`disable_processing`](#function-disable_processing)
- [`task_schedule`](#function-task_schedule)
- [`spawn_local`](#function-spawn_local)
- [`spawn_local_with_priority`](#function-spawn_local_with_priority)
- [`spawn`](#function-spawn)
- [`spawn_with_priority`](#function-spawn_with_priority)
- [`start_local`](#function-start_local)
- [`start_local_with_priority`](#function-start_local_with_priority)
- [`start_local_on_result_with_priority`](#function-start_local_on_result_with_priority)
- [`run_jobs`](#function-run_jobs)
- [`has_jobs_with_priority`](#function-has_jobs_with_priority)
- [`current_dispatcher`](#function-current_dispatcher)
- [`from_thread`](#function-from_thread)
- [`ui_thread`](#function-ui_thread)
- [`now`](#function-now)
- [`current_priority`](#function-current_priority)
- [`set_current_priority`](#function-set_current_priority)
- [`to_task_scheduler`](#function-to_task_scheduler)
- [`to_task_scheduler_with_priority`](#function-to_task_scheduler_with_priority)

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

### supports_run_loops

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

Whether the platform implementation can run nested event loops. When
this is `false`, `push_frame` and
`main_loop` are not available.

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

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

### check_access

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

Checks that the current thread is the dispatcher thread.

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

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

### verify_access

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

Checks that the current thread is the dispatcher thread and panics if
not.

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

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

### thread

```rust
fn thread(self: &Self) -> ThreadId
```

The thread this dispatcher belongs to.

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

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

### unhandled_exception

```rust
fn unhandled_exception(self: &Self, handler: impl Fn(&DispatcherUnhandledExceptionEventArgs<'a>) -> () + 'static) -> Rc<dyn IDisposable>
```

Occurs when a callback posted with `post` or
`post_local` panics and the panic is not caught.

A handler can mark the panic as handled, which stops it from being
re-raised on the dispatcher thread. Handlers must be written with
care to avoid secondary panics.

Callbacks run through `invoke`/`invoke_async` do not raise this
event: their panic is delivered to whoever waits for the operation.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### unhandled_exception_filter

```rust
fn unhandled_exception_filter(self: &Self, handler: impl Fn(&DispatcherUnhandledExceptionFilterEventArgs<'a>) -> () + 'static) -> Rc<dyn IDisposable>
```

Occurs first when a posted callback panics, to decide whether
`unhandled_exception` is raised at all.

The filter runs regardless of whether there are
`unhandled_exception` handlers. Setting
`request_catch`
to `false` skips the `unhandled_exception` event.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### invoke

```rust
fn invoke<R: Send + 'static>(self: &Self, callback: impl FnOnce() -> R + Send + 'static) -> Result<R, Canceled>
```

Executes the specified callback synchronously on the thread that the
dispatcher was created on, at `DispatcherPriority::SEND`.

Returns `Err` when the operation was aborted before it ran (for
instance because the dispatcher has shut down).
## Panics
Re-raises the panic of the callback.

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

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

### invoke_with_priority

```rust
fn invoke_with_priority<R: Send + 'static>(self: &Self, callback: impl FnOnce() -> R + Send + 'static, priority: DispatcherPriority) -> Result<R, Canceled>
```

Executes the specified callback synchronously with the specified
priority on the thread that the dispatcher was created on.

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

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

### invoke_with_cancellation

```rust
fn invoke_with_cancellation<R: Send + 'static>(self: &Self, callback: impl FnOnce() -> R + Send + 'static, priority: DispatcherPriority, cancellation_token: &CancellationToken) -> Result<R, Canceled>
```

Executes the specified callback synchronously with the specified
priority on the thread that the dispatcher was created on.

`cancellation_token` cancels the operation as long as it has not
started. Returns `Err` when the token is already canceled.

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

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

### invoke_with_timeout

```rust
fn invoke_with_timeout<R: Send + 'static>(self: &Self, callback: impl FnOnce() -> R + Send + 'static, priority: DispatcherPriority, cancellation_token: &CancellationToken, timeout: Duration) -> Result<R, DispatcherInvokeError>
```

Executes the specified callback synchronously with the specified
priority on the thread that the dispatcher was created on, giving up
when the operation has not started within `timeout`.

The timeout only applies to the time the operation spends in the
queue: once it has started, the call waits for it to complete. When
the operation is still pending after `timeout` it is aborted and
`DispatcherInvokeError::Timeout` is returned.

On the dispatcher thread the queue is pumped while waiting and the
timeout is measured with the dispatcher clock.

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

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

### invoke_local

```rust
fn invoke_local<R: 'static>(self: &Self, callback: impl FnOnce() -> R + 'static) -> Result<R, Canceled>
```

Like `invoke` for callbacks that are not `Send`.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### invoke_local_with_priority

```rust
fn invoke_local_with_priority<R: 'static>(self: &Self, callback: impl FnOnce() -> R + 'static, priority: DispatcherPriority) -> Result<R, Canceled>
```

Like `invoke_with_priority` for
callbacks that are not `Send`.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### invoke_local_with_cancellation

```rust
fn invoke_local_with_cancellation<R: 'static>(self: &Self, callback: impl FnOnce() -> R + 'static, priority: DispatcherPriority, cancellation_token: &CancellationToken) -> Result<R, Canceled>
```

Like `invoke_with_cancellation` for
callbacks that are not `Send`.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### invoke_local_with_timeout

```rust
fn invoke_local_with_timeout<R: 'static>(self: &Self, callback: impl FnOnce() -> R + 'static, priority: DispatcherPriority, cancellation_token: &CancellationToken, timeout: Duration) -> Result<R, DispatcherInvokeError>
```

Like `invoke_with_timeout` for callbacks
that are not `Send`.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### invoke_async

```rust
fn invoke_async<R: Send + 'static>(self: &Self, callback: impl FnOnce() -> R + Send + 'static) -> DispatcherOperation<R>
```

Executes the specified callback asynchronously on the thread that the
dispatcher was created on, at `DispatcherPriority::DEFAULT`.

The returned operation can be awaited, waited for, aborted and
re-prioritized.

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

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

### invoke_async_with_priority

```rust
fn invoke_async_with_priority<R: Send + 'static>(self: &Self, callback: impl FnOnce() -> R + Send + 'static, priority: DispatcherPriority) -> DispatcherOperation<R>
```

Executes the specified callback asynchronously with the specified
priority on the thread that the dispatcher was created on.

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

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

### invoke_async_with_cancellation

```rust
fn invoke_async_with_cancellation<R: Send + 'static>(self: &Self, callback: impl FnOnce() -> R + Send + 'static, priority: DispatcherPriority, cancellation_token: &CancellationToken) -> DispatcherOperation<R>
```

Executes the specified callback asynchronously with the specified
priority on the thread that the dispatcher was created on.

`cancellation_token` aborts the operation as long as it has not
started.

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

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

### invoke_async_local

```rust
fn invoke_async_local<R: 'static>(self: &Self, callback: impl FnOnce() -> R + 'static) -> DispatcherOperation<R>
```

Like `invoke_async` for callbacks that are not
`Send`.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### invoke_async_local_with_priority

```rust
fn invoke_async_local_with_priority<R: 'static>(self: &Self, callback: impl FnOnce() -> R + 'static, priority: DispatcherPriority) -> DispatcherOperation<R>
```

Like `invoke_async_with_priority`
for callbacks that are not `Send`.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### invoke_async_local_with_cancellation

```rust
fn invoke_async_local_with_cancellation<R: 'static>(self: &Self, callback: impl FnOnce() -> R + 'static, priority: DispatcherPriority, cancellation_token: &CancellationToken) -> DispatcherOperation<R>
```

Like
`invoke_async_with_cancellation`
for callbacks that are not `Send`.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### invoke_async_task

```rust
fn invoke_async_task<F, Fut>(self: &Self, callback: F) -> DispatcherTask<<Fut as >::Output>
where F: FnOnce() -> Fut + Send + 'static,
      Fut: Future + 'static,
      <Fut as >::Output: Send + 'static
```

Executes the specified callback on the dispatcher thread and then
runs the future it returns there, at
`DispatcherPriority::DEFAULT`.

The returned task completes when the future has completed; see
`invoke_async_task_with_priority`.

Deprecated: `spawn` does the same and gives a `JoinHandle`.

> **Deprecated since 0.5.0.** use `Dispatcher::spawn`, which gives a `JoinHandle` (a panic of the future is `JoinError::Panicked`, a value)

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

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

### invoke_async_task_with_priority

```rust
fn invoke_async_task_with_priority<F, Fut>(self: &Self, callback: F, priority: DispatcherPriority) -> DispatcherTask<<Fut as >::Output>
where F: FnOnce() -> Fut + Send + 'static,
      Fut: Future + 'static,
      <Fut as >::Output: Send + 'static
```

Executes the specified callback with the specified priority on the
dispatcher thread and then runs the future it returns there.

The callback can come from any thread; the future it creates never
leaves the dispatcher thread and does not have to be `Send`. The
future is polled for the first time right after the callback, inside
the same job, and afterwards from jobs of the same priority.

The returned task completes when the future has completed. It is
canceled when the operation is aborted before the callback ran or the
dispatcher shuts down before the future is done, and it fails with
the panic of the callback or the future.

The task is a task of the dispatcher
(`spawn_with_priority`), with a handle
that keeps the contract of `DispatcherTask`.

Deprecated: `spawn_with_priority` does the
same and gives a `JoinHandle`.

> **Deprecated since 0.5.0.** use `Dispatcher::spawn_with_priority`, which gives a `JoinHandle` (a panic of the future is `JoinError::Panicked`, a value)

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

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

### invoke_async_task_local

```rust
fn invoke_async_task_local<F, Fut>(self: &Self, callback: F) -> DispatcherTask<<Fut as >::Output>
where F: FnOnce() -> Fut + 'static,
      Fut: Future + 'static,
      <Fut as >::Output: 'static
```

Like `invoke_async_task` for callbacks and
results that are not `Send`.
## Panics
Panics when called from a thread other than the dispatcher thread.

Deprecated: `spawn_local_with_priority(async move { callback().await },
DispatcherPriority::DEFAULT)` does the same (the callback runs in the
first poll, a job at that priority) and gives a `JoinHandle`.

> **Deprecated since 0.5.0.** use `Dispatcher::spawn_local_with_priority(async move { callback().await }, DispatcherPriority::DEFAULT)`, which gives a `JoinHandle`

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

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

### invoke_async_task_local_with_priority

```rust
fn invoke_async_task_local_with_priority<F, Fut>(self: &Self, callback: F, priority: DispatcherPriority) -> DispatcherTask<<Fut as >::Output>
where F: FnOnce() -> Fut + 'static,
      Fut: Future + 'static,
      <Fut as >::Output: 'static
```

Like
`invoke_async_task_with_priority`
for callbacks and results that are not `Send`.
## Panics
Panics when called from a thread other than the dispatcher thread.

Deprecated: `spawn_local_with_priority(async move { callback().await },
priority)` does the same and gives a `JoinHandle`.

> **Deprecated since 0.5.0.** use `Dispatcher::spawn_local_with_priority(async move { callback().await }, priority)`, which gives a `JoinHandle`

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

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

### post

```rust
fn post(self: &Self, action: impl FnOnce() -> () + Send + 'static, priority: DispatcherPriority)
```

Posts an action that will be invoked on the dispatcher thread.

Can be called from any thread. A panic raised by the action goes
through the unhandled-exception events of the dispatcher.

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

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

### post_local

```rust
fn post_local(self: &Self, action: impl FnOnce() -> () + 'static, priority: DispatcherPriority)
```

Posts an action that is not `Send` to be invoked on the dispatcher
thread.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### await_with_priority

```rust
fn await_with_priority<F: Future>(self: &Self, task: F, priority: DispatcherPriority) -> DispatcherPriorityTaskAwaitable<F>
```

Returns a future that awaits `task` and then resumes the awaiting
code from a job of this dispatcher with the given priority, yielding
the output of `task`.

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

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

### resume

```rust
fn resume(self: &Self) -> DispatcherPriorityAwaitable
```

Returns a future that resumes on this dispatcher's thread at
`DispatcherPriority::BACKGROUND` when awaited.

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

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

### resume_with_priority

```rust
fn resume_with_priority(self: &Self, priority: DispatcherPriority) -> DispatcherPriorityAwaitable
```

Returns a future that resumes on this dispatcher's thread at the
given priority when awaited.

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

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

### yield_now

```rust
fn yield_now() -> DispatcherPriorityAwaitable
```

Returns a future that yields to the current dispatcher, letting it
process other work, and resumes at `DispatcherPriority::BACKGROUND`.

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

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

### yield_with_priority

```rust
fn yield_with_priority(priority: DispatcherPriority) -> DispatcherPriorityAwaitable
```

Returns a future that yields to the current dispatcher and resumes at
the given priority.

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

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

### shutdown_started

```rust
fn shutdown_started(self: &Self, handler: impl Fn(&Arc<Dispatcher>) -> () + 'static) -> Rc<dyn IDisposable>
```

Raised when the dispatcher is shutting down.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### shutdown_finished

```rust
fn shutdown_finished(self: &Self, handler: impl Fn(&Arc<Dispatcher>) -> () + 'static) -> Rc<dyn IDisposable>
```

Raised when the dispatcher is shut down.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### push_frame

```rust
fn push_frame(self: &Self, frame: &Arc<DispatcherFrame>)
```

Push an execution frame.
## Panics
Panics when the platform implementation does not support run loops
(see `supports_run_loops`), when the
dispatcher has shut down, when processing is disabled and when called
from another thread.

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

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

### main_loop

```rust
fn main_loop(self: &Self, cancellation_token: &CancellationToken)
```

Runs the dispatcher's main loop until `cancellation_token` is
canceled.
## Panics
See `push_frame`.

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

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

### exit_all_frames

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

Requests that all nested frames exit.

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

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

### begin_invoke_shutdown

```rust
fn begin_invoke_shutdown(self: &Self, priority: DispatcherPriority)
```

Begins the process of shutting down the dispatcher.

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

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

### invoke_shutdown

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

Initiates the shutdown process of the dispatcher synchronously.

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

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

### disable_processing

```rust
fn disable_processing(self: &Self) -> DispatcherProcessingDisabled
```

Disable the event processing of the dispatcher.

This is an advanced method intended to eliminate the chance of
unrelated reentrancy. While processing is disabled no one is allowed
to push a frame and no job processing is permitted. Processing is
enabled again when the returned value is disposed or dropped.

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

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

### task_schedule

```rust
fn task_schedule(self: &Self, priority: DispatcherPriority) -> Arc<dyn Schedule>
```

The schedule of the tasks of this dispatcher at `priority`: every poll of a task given to it
is a job posted at that priority, and the dispatcher aborts the task when it shuts down;
work that is not `Send` (`Schedule::schedule_local`) is a job posted with
`post_local`. It is the current schedule of the jobs of that priority
(`ferroui_system::task::current_schedule`); on the dispatcher thread there is one schedule
per priority.

For `ferroui_system::task::spawn_local_on`, on the dispatcher thread; with
`FirstPoll::Now` the future runs up to its first pending await inside the spawning call.
A task given to it on another thread is aborted at once.

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

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

### spawn_local

```rust
fn spawn_local<F>(self: &Self, future: F) -> JoinHandle<<F as >::Output>
where F: Future + 'static,
      <F as >::Output: 'static
```

Runs `future` on this dispatcher at the priority of the job that calls this
(`DispatcherPriority::DEFAULT` outside of a job), and gives its handle; see
`spawn_local_with_priority`.
## Panics
When called from a thread other than the dispatcher thread.

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

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

### spawn_local_with_priority

```rust
fn spawn_local_with_priority<F>(self: &Self, future: F, priority: DispatcherPriority) -> JoinHandle<<F as >::Output>
where F: Future + 'static,
      <F as >::Output: 'static
```

Runs `future`, which need not be `Send`, on this dispatcher, and gives its handle. Its
first poll is a job posted at `priority`, and so is every poll that a wake queues, from any
thread. The handle is a future of the output, or of a
`JoinError`: canceled when the task is aborted or the
dispatcher shuts down first, panicked when the future panics. Dropping the handle detaches
the task, which keeps running.
## Panics
When called from a thread other than the dispatcher thread.

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

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

### spawn

```rust
fn spawn<C, F>(self: &Self, create: C) -> JoinHandle<<F as >::Output>
where C: FnOnce() -> F + Send + 'static,
      F: Future + 'static,
      <F as >::Output: Send + 'static
```

Runs the future that `create` makes on this dispatcher at `DispatcherPriority::DEFAULT`,
from any thread; see `spawn_with_priority`.

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

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

### spawn_with_priority

```rust
fn spawn_with_priority<C, F>(self: &Self, create: C, priority: DispatcherPriority) -> JoinHandle<<F as >::Output>
where C: FnOnce() -> F + Send + 'static,
      F: Future + 'static,
      <F as >::Output: Send + 'static
```

Runs the future that `create` makes on this dispatcher, and gives its handle; callable from
any thread. `create` is `Send` and runs in a job posted at `priority`; the future it makes
need not be `Send`, never leaves the dispatcher thread, and is polled for the first time
inside that job, then from jobs of the same priority (what the deprecated
`invoke_async_task_with_priority` does, with a `JoinHandle`). A panic of
`create` faults the task like a panic of the future; the task is canceled when the
dispatcher shuts down before the job runs.

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

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

### start_local

```rust
fn start_local<F>(self: &Self, future: F) -> JoinHandle<<F as >::Output>
where F: Future + 'static,
      <F as >::Output: 'static
```

Starts `future` on this dispatcher at the priority of the job that calls this
(`DispatcherPriority::DEFAULT` outside of a job), and gives its handle; see
`start_local_with_priority`.
## Panics
When called from a thread other than the dispatcher thread.

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

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

### start_local_with_priority

```rust
fn start_local_with_priority<F>(self: &Self, future: F, priority: DispatcherPriority) -> JoinHandle<<F as >::Output>
where F: Future + 'static,
      <F as >::Output: 'static
```

Starts `future`, which need not be `Send`, on this dispatcher the way calling an
asynchronous method does, and gives its handle: the future is polled for the first time
before this returns (`FirstPoll::Now`), so it runs up to its first pending await inside
the call (and the handle is finished when there is none); every later poll is a job posted
at `priority` by a wake, from any thread. Otherwise the task is the one of
`spawn_local_with_priority`: a panic of the future is
`JoinError::Panicked`, an abort or the
shutdown of the dispatcher is `JoinError::Canceled`,
and dropping the handle detaches the task.

What `DispatcherTaskScheduler::start_local` (deprecated) did, with a `JoinHandle`.
## Panics
When called from a thread other than the dispatcher thread.

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

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

### start_local_on_result_with_priority

```rust
fn start_local_on_result_with_priority<F, T>(self: &Self, future: F, priority: DispatcherPriority) -> JoinHandle<T>
where F: Future<Output = Result<T, ferroui_system::task::JoinError>> + 'static,
      T: 'static
```

`start_local_with_priority` for a future whose
failure is a value: an `Err` of the future fails the handle with that
`JoinError`, as a panic of the future does, but without
unwinding, so the task fails the same way in a build that aborts on panic (#567).
## Panics
When called from a thread other than the dispatcher thread.

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

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

### run_jobs

```rust
fn run_jobs(self: &Self, priority: Option<DispatcherPriority>)
```

Force-runs all dispatcher operations ignoring any pending OS events,
use with caution.

`None` runs every active job.

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

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

### has_jobs_with_priority

```rust
fn has_jobs_with_priority(self: &Self, priority: DispatcherPriority) -> bool
```

Whether a job with at least the given priority is queued.

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

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

### current_dispatcher

```rust
fn current_dispatcher() -> Arc<Dispatcher>
```

The dispatcher of the calling thread. It is created when the thread
does not have one yet and then lives until the thread exits.

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

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

### from_thread

```rust
fn from_thread(thread: ThreadId) -> Option<Arc<Dispatcher>>
```

The dispatcher of `thread`, if that thread has one.

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

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

### ui_thread

```rust
fn ui_thread() -> Arc<Dispatcher>
```

Gets the dispatcher for the UI thread: the first dispatcher that was
created in the process.

Control and library authors are encouraged to use
`current_dispatcher` and the dispatcher of
the object at hand instead.

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

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

### now

```rust
fn now(self: &Self) -> i64
```

The current time of the platform implementation, in milliseconds.

Dispatcher thread only; a dispatcher that has been reset reports 0.

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

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

### current_priority

```rust
fn current_priority() -> Option<DispatcherPriority>
```

The priority of the dispatcher job that runs on the calling thread (`None` outside of a
job): what asynchronous code started by the job continues at. Also the priority set with
`set_current_priority` for the code that runs outside of a
job, and the priority of a nested frame between its jobs (`DispatcherPriority::NORMAL`).

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

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

### set_current_priority

```rust
fn set_current_priority(priority: Option<DispatcherPriority>) -> Option<DispatcherPriority>
```

Sets the priority of the code that runs on the calling thread outside of a dispatcher job,
and gives the previous one: the dispatcher of the thread at that priority becomes the
current schedule of the thread (`ferroui_system::task::current_schedule`), which the
tasks spawned there and the reactive libraries continue in; `None` clears both. What the
application does when it starts (at `DispatcherPriority::NORMAL`, unless the thread has a
priority), as the context that the upstream application installs; the jobs of the
dispatcher set their own priority while they run, and restore this one.

A priority creates the dispatcher of the calling thread when it has none.

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

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

### to_task_scheduler

```rust
fn to_task_scheduler(self: &Self) -> DispatcherTaskScheduler
```

Gets a scheduler which runs futures on this dispatcher. The priority
is the one of the job that calls this (`Dispatcher::current_priority`),
`DispatcherPriority::DEFAULT` outside of a job.

Deprecated: `Dispatcher::spawn_local`, `Dispatcher::start_local` and
`Dispatcher::spawn_with_priority` at that priority give a `JoinHandle`.

> **Deprecated since 0.5.0.** use `Dispatcher::spawn_local`, `start_local` or `spawn_with_priority`, which give a `JoinHandle`

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

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

### to_task_scheduler_with_priority

```rust
fn to_task_scheduler_with_priority(self: &Self, priority: DispatcherPriority) -> DispatcherTaskScheduler
```

Gets a scheduler which runs futures on this dispatcher with the
specified priority.

Deprecated: `Dispatcher::spawn_local_with_priority`,
`Dispatcher::start_local_with_priority` and
`Dispatcher::spawn_with_priority` give a `JoinHandle`.

> **Deprecated since 0.5.0.** use `Dispatcher::spawn_local_with_priority`, `start_local_with_priority` or `spawn_with_priority`, which give a `JoinHandle`

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

## 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`
- [`IDispatcher`](/docs/0.5.0/api/ferroui-base/threading/trait-idispatcher/)
- `Debug`

## Availability

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