# FerroSynchronizationContext

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

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

```rust
struct FerroSynchronizationContext
```

A dispatcher together with the priority at which work handed to it is
queued.

The *current* context of a thread tells asynchronous code where and at
which priority to continue. While the dispatcher executes a job, the
current context is the dispatcher's context for the priority of that job;
futures started without an explicit priority (see
`Dispatcher::spawn_local`) therefore continue at the priority of
the job that started them.

What the reference implementation additionally does in its context -
replacing the blocking wait of the runtime with one that does not pump
messages - has no counterpart: blocking primitives never run a message
pump here.

Deprecated: the current priority is `Dispatcher::current_priority` (and
`Dispatcher::set_current_priority`), posting is `Dispatcher::post` and
`Dispatcher::post_local` at that priority, and the code that does not
know the dispatcher takes the current schedule of `ferroui-system`
(`ferroui_system::task::current_schedule`, the dispatcher's
`task_schedule` of the priority).

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

> **Deprecated since 0.5.0.** use `Dispatcher::current_priority`, `Dispatcher::post`/`post_local` at that priority, or the dispatcher's `task_schedule(priority)`

## Members

- [`new`](#function-new)
- [`with_priority`](#function-with_priority)
- [`with_dispatcher`](#function-with_dispatcher)
- [`priority`](#function-priority)
- [`dispatcher`](#function-dispatcher)
- [`current`](#function-current)
- [`set_current`](#function-set_current)
- [`auto_install`](#function-auto_install)
- [`set_auto_install`](#function-set_auto_install)
- [`install_if_needed`](#function-install_if_needed)
- [`post`](#function-post)
- [`post_local`](#function-post_local)
- [`send`](#function-send)
- [`send_local`](#function-send_local)
- [`to_task_scheduler`](#function-to_task_scheduler)
- [`ensure`](#function-ensure)
- [`ensure_with_dispatcher`](#function-ensure_with_dispatcher)

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

### new

```rust
fn new() -> Arc<Self>
```

Creates a context for the current thread's dispatcher at
`DispatcherPriority::DEFAULT`.

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

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

### with_priority

```rust
fn with_priority(priority: DispatcherPriority) -> Arc<Self>
```

Creates a context for the current thread's dispatcher.

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

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

### with_dispatcher

```rust
fn with_dispatcher(dispatcher: &Arc<Dispatcher>, priority: DispatcherPriority) -> Arc<Self>
```



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

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

### priority

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

The priority at which this context queues work.

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

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

### dispatcher

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



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

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

### current

```rust
fn current() -> Option<Arc<FerroSynchronizationContext>>
```

The context of the calling thread.

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

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

### set_current

```rust
fn set_current(context: Option<Arc<FerroSynchronizationContext>>) -> Option<Arc<FerroSynchronizationContext>>
```

Sets the context of the calling thread and returns the previous one. The dispatcher of the
context at its priority becomes the current schedule of the thread
(`ferroui_system::task::current_schedule`); `None` clears it.

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

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

### auto_install

```rust
fn auto_install() -> bool
```

Controls whether `install_if_needed` does
anything.

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

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

### set_auto_install

```rust
fn set_auto_install(value: bool)
```



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

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

### install_if_needed

```rust
fn install_if_needed()
```

Makes the `DispatcherPriority::NORMAL` context of the current
thread's dispatcher the current context, unless the thread already
has one.

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

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

### post

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

Queues `callback` on the dispatcher at the priority of this context.

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

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

### post_local

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

Like `post` 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/ferro_synchronization_context.rs#L243)

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

### send

```rust
fn send(self: &Self, callback: impl FnOnce() -> () + Send + 'static)
```

Runs `callback` on the dispatcher thread and waits for it.

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

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

### send_local

```rust
fn send_local(self: &Self, callback: impl FnOnce() -> () + 'static)
```

Like `send` for callbacks that are not `Send`: runs
`callback` right away.
## Panics
Panics when called from a thread other than the dispatcher thread.

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

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

### to_task_scheduler

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

The scheduler that runs futures on the dispatcher at the priority of
this context.

> **Deprecated since 0.5.0.** use the dispatcher's `spawn_local_with_priority`, `spawn_with_priority` or `start_local_with_priority` at the priority of the context

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

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

### ensure

```rust
fn ensure(priority: DispatcherPriority) -> RestoreContext
```

Makes sure that the current context of the calling thread is the one
of the current dispatcher for `priority`. Disposing or dropping the
returned value restores the previous context.

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

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

### ensure_with_dispatcher

```rust
fn ensure_with_dispatcher(dispatcher: &Dispatcher, priority: DispatcherPriority) -> RestoreContext
```

Makes sure that the current context of the calling thread is the one
of `dispatcher` for `priority`. Disposing or dropping the returned
value restores the previous context.
## Panics
Panics when the context has to change and the calling thread is not
the dispatcher thread.

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

## 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`
- [`SynchronizationContext`](/docs/0.5.0/api/ferroui-system/threading/trait-synchronizationcontext/)

## Availability

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