# Shared

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-system/task/struct-shared/

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

```rust
struct Shared<T>
```

The outcome of a task for several observers (`JoinHandle::shared`),
or of code that ends it by hand (`Shared::channel`, the role of `Task<T>` and
`TaskCompletionSource<T>` of .NET in the reactive libraries): each clone is a future of a copy of
it, and `on_finished` adds synchronous continuations
(`ContinueWith` with `TaskContinuationOptions.ExecuteSynchronously`).

When it ends, the continuations run first, in the order they were added, and then the futures
awaiting the outcome are woken, in the order they awaited it: on the thread of the `Shared`,
inside the call that ends it when it ends there (the task's end, `SharedSender::send`),
otherwise when that thread runs `run_pending`. The payload of a panic
reaches each observer as its message, a `String`. A `Shared` belongs to the thread that made it.

The outcome of a future that can fail is part of `T`: the asynchronous forms of the reactive
libraries give a `Shared<Result<T, ObservableError>>`, whose `flatten` is a
future of `Result<T, ObservableError>`.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L47)

## Members

- [`channel`](#function-channel)
- [`ready`](#function-ready)
- [`from_outcome`](#function-from_outcome)
- [`is_finished`](#function-is_finished)
- [`on_finished`](#function-on_finished)
- [`remove_on_finished`](#function-remove_on_finished)
- [`abort`](#function-abort)
- [`ptr_eq`](#function-ptr_eq)
- [`outcome`](#function-outcome)
- [`flatten`](#function-flatten)
- [`result`](#function-result)

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

### channel

```rust
fn channel() -> (SharedSender<T>, Self)
```

A `Shared` that no task ends, and the `SharedSender` that ends it: the port of
`TaskCompletionSource<T>` and its `Task` for code of one thread whose observers continue
synchronously (the reactive libraries).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L82)

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

### ready

```rust
fn ready(value: T) -> Self
```

A `Shared` that has ended with `value` (`Task.FromResult`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L88)

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

### from_outcome

```rust
fn from_outcome(outcome: Result<T, JoinError>) -> Self
```

A `Shared` that has ended with `outcome`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L93)

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

### is_finished

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

Whether it has ended, and its observers have been told.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L124)

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

### on_finished

```rust
fn on_finished(self: &Self, callback: impl FnOnce(&Result<T, JoinError>) -> () + 'static) -> Option<OnFinishedId>
```

Runs `callback` with the outcome when it ends, before the awaiting futures are woken, or at
once when it has ended. The id removes a continuation that has not run
(`remove_on_finished`, the cancellation token of `ContinueWith`);
`None` when it ran at once.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L132)

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

### remove_on_finished

```rust
fn remove_on_finished(self: &Self, id: OnFinishedId) -> bool
```

Removes a continuation that has not run; false when it has run or was removed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L144)

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

### abort

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

Aborts the task (see `JoinHandle::abort`); nothing for a
`Shared` that no task ends.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L156)

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

### ptr_eq

```rust
fn ptr_eq(this: &Self, other: &Self) -> bool
```

Whether two handles are of the same outcome.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L165)

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

### outcome

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

A copy of the outcome when it has ended.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L172)

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

### flatten

```rust
fn flatten(self: Self) -> Flatten<T>
```

A future of the outcome as one result (`Flatten`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L198)

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

### result

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

The outcome as one result when it has ended: an abort is the error
`Canceled`, a panic a `TaskWorkError` with its message.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/task/shared.rs#L204)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `IntoFuture`
- `ToOwned`
- `Clone`
- `Future`
- `Debug`
- `From<Task<T>>`

## Availability

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