# SchedulerExtensions

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui-testing/trait-schedulerextensions/

**trait** · [`ferroui-reactiveui-testing`](/docs/0.5.0/api/ferroui-reactiveui-testing/) · v0.5.0

```rust
trait SchedulerExtensions
```

Runs code with a scheduler as both schedulers of `RxSchedulers`, the main thread scheduler
and the task pool scheduler (`SchedulerExtensions`).

It is implemented for a scheduler handle (`Rc<dyn IScheduler>`, `Rc<S>`) and for the
`TestScheduler` of `ferroui-reactive-testing`; the block receives the scheduler it was called
on.

Deviation (DEVIATIONS.md, ReactiveUI): the schedulers of `RxSchedulers` are per thread, so the
scheduler is the scheduler of the current thread only.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/scheduler_extensions.rs#L31)

## Members

- [`as_scheduler`](#function-as_scheduler)
- [`with_scheduler`](#function-with_scheduler)
- [`with`](#function-with)
- [`with_async`](#function-with_async)

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

### as_scheduler

```rust
fn as_scheduler(self: &Self) -> Rc<dyn IScheduler>
```

The scheduler as the handle that `RxSchedulers` holds.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/scheduler_extensions.rs#L33)

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

### with_scheduler

```rust
fn with_scheduler(self: &Self) -> Rc<dyn IDisposable>
```

Makes the scheduler both schedulers of `RxSchedulers` until the returned disposable is
disposed, which restores the schedulers set before (`WithScheduler`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/scheduler_extensions.rs#L37)

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

### with

```rust
fn with<R>(self: &Self, block: impl FnOnce(&Self) -> R) -> R
```

Runs `block` with the scheduler as both schedulers of `RxSchedulers` and returns its
result; the schedulers set before are restored afterwards, also when `block` panics
(`With<TRet>(Func<T, TRet>)`, and `With(Action<T>)` with a block that returns `()`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/scheduler_extensions.rs#L54)

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

### with_async

```rust
fn with_async<R: Clone + 'static, Fut: Future<Output = Result<R, ObservableError>> + 'static>(self: &Self, block: impl FnOnce(&Self) -> Fut) -> Shared<Result<R, ObservableError>>
```

Runs `block` with the scheduler as both schedulers of `RxSchedulers` until the task it
returns ends, and gives the outcome of that task (`WithAsync<TRet>(Func<T, Task<TRet>>)`,
and `WithAsync(Func<T, Task>)` with `R = ()`): the block gives a future of a
`Result<R, ObservableError>`, which runs as a task of the thread, and the task is the
`Shared` of its result.

A panic of `block` ends the returned task with the error of the panic
(`PanicError`), as an exception thrown in an `async` method faults its task; the
schedulers are restored in every case.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/scheduler_extensions.rs#L68)

## Trait implementations

- [`SchedulerExtensions`](/docs/0.5.0/api/ferroui-reactiveui-testing/trait-schedulerextensions/)

## Availability

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