# AsyncSubject

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactive/subjects/struct-asyncsubject/

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

```rust
struct AsyncSubject<T>
```

A subject that keeps the last value and hands it, with the end, to every observer once the
sequence has ended (`AsyncSubject<T>`).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/async_subject.rs#L15)

## Members

- [`new`](#function-new)
- [`is_completed`](#function-is_completed)
- [`get_result`](#function-get_result)
- [`get_awaiter`](#function-get_awaiter)
- [`as_observable`](#function-as_observable)
- [`as_observer`](#function-as_observer)

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

### new

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/async_subject.rs#L35)

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

### is_completed

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

Whether the subject has ended (`IsCompleted`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/async_subject.rs#L44)

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

### get_result

```rust
fn get_result(self: &Self) -> Result<Option<T>, ObservableError>
```

The last value of an ended subject (`GetResult`): the error when it ended with one, `None`
when it ended without a value (upstream throws `InvalidOperationException`). Panics when the
subject has not ended, where upstream blocks until it does (a wait on the only thread would
never end).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/async_subject.rs#L52)

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

### get_awaiter

```rust
fn get_awaiter(self: &Self) -> Shared<Result<T, ObservableError>>
```

The awaiter of the subject (`GetAwaiter`): a task, the `Shared` of a result, that ends
when the subject ends, with its last value, with its error (a cancellation's included), or
with `SequenceError::NoElements` when it ended without a value (`GetResult`'s
`InvalidOperationException`). `async` code awaits its `flatten()`.

Upstream's subject is its own awaiter; its members are those of the task: `IsCompleted` is
`Shared::is_finished`, `OnCompleted(Action)` is `Shared::on_finished` and `GetResult` is
`Shared::result` once the task has ended.

The awaiter captures the current `SynchronizationContext` of the thread, as upstream's
`AwaitObserver` does, which is its current schedule (`ferroui_system::task::current_schedule`;
in a dispatcher job the dispatcher at the priority of the job): when there is one, the end of
the subject is posted to it (with `schedule_local`), and the task
ends, running its continuations, when the schedule runs that work; without one, the task ends
where the subject does.

Deviation (DEVIATIONS.md, Reactive): upstream posts only the continuation of `OnCompleted`
and its `IsCompleted` is true as soon as the subject has ended; the task of the port ends
when the posted work runs, so its `is_finished` is false until then.
The context is captured when the awaiter is made, where upstream captures it when the
continuation is given (`OnCompleted`).
## Panics
When the subject is disposed (`ObjectDisposedException`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/async_subject.rs#L88)

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

### as_observable

```rust
fn as_observable(self: &Rc<Self>) -> Rc<dyn IObservable<T>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/async_subject.rs#L96)

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

### as_observer

```rust
fn as_observer(self: &Rc<Self>) -> Rc<dyn IObserver<T>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/subjects/async_subject.rs#L100)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ISubjectHandle<A, B>`](/docs/0.5.0/api/ferroui-reactive/subjects/trait-isubjecthandle/)
- [`ISubject<A, B>`](/docs/0.5.0/api/ferroui-reactive/subjects/trait-isubject/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`SubscribeGuard<T>`](/docs/0.5.0/api/ferroui-base/reactive/use-subscribeguard/)
- [`IObserver<T>`](/docs/0.5.0/api/ferroui-base/reactive/use-iobserver/)
- [`IObservable<T>`](/docs/0.5.0/api/ferroui-base/reactive/use-iobservable/)
- [`IDisposable`](/docs/0.5.0/api/ferroui-base/reactive/use-idisposable/)
- [`SubjectBase<T>`](/docs/0.5.0/api/ferroui-reactive/subjects/trait-subjectbase/)

## Availability

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