# Task

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

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

```rust
struct Task<T>
```

The outcome of an asynchronous operation (`Task<TResult>`; `Task` is `Task<()>`): a shared
handle that ends once, with a result, an error or a cancellation.

Continuations (`continue_with`) run synchronously when the task ends
(`TaskContinuationOptions.ExecuteSynchronously`); a task is also a `Future` of its outcome.
Tasks belong to the thread that made them, like the observables
(docs/porting/reactive.md, section 5.8).

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

> **Deprecated since 0.5.0.** use `ferroui_system::task::Shared<Result<T, ObservableError>>` (`Shared::channel`, `JoinHandle::shared`, `Shared::on_finished`); `Shared::from(task)` converts

## Members

- [`from_result`](#function-from_result)
- [`from_exception`](#function-from_exception)
- [`from_canceled`](#function-from_canceled)
- [`spawn_local`](#function-spawn_local)
- [`id`](#function-id)
- [`status`](#function-status)
- [`is_completed`](#function-is_completed)
- [`is_completed_successfully`](#function-is_completed_successfully)
- [`is_faulted`](#function-is_faulted)
- [`is_canceled`](#function-is_canceled)
- [`exception`](#function-exception)
- [`result`](#function-result)
- [`continue_with`](#function-continue_with)
- [`remove_continuation`](#function-remove_continuation)

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

### from_result

```rust
fn from_result(result: T) -> Self
```

A task that has ended with `result` (`Task.FromResult`).

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

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

### from_exception

```rust
fn from_exception(error: ObservableError) -> Self
```

A task that has ended with `error` (`Task.FromException`); a cancellation (`Canceled`,
`TaskCanceledError`) makes it canceled.

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

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

### from_canceled

```rust
fn from_canceled() -> Self
```

A canceled task (`Task.FromCanceled`).

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

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

### spawn_local

```rust
fn spawn_local(future: impl Future<Output = Result<T, ObservableError>> + 'static) -> Self
```

Runs `future` on the current thread and gives its task (the counterpart of an `async`
method): see `spawn_local`.

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

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

### id

```rust
fn id(self: &Self) -> u64
```

The identity of the task (`Id`).

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

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

### status

```rust
fn status(self: &Self) -> TaskStatus
```

The state of the task (`Status`).

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

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

### is_completed

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

Whether the task has ended, in any way (`IsCompleted`).

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

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

### is_completed_successfully

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

Whether the task has ended with a result (`IsCompletedSuccessfully`).

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

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

### is_faulted

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

Whether the task has ended with an error (`IsFaulted`).

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

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

### is_canceled

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

Whether the task has been canceled (`IsCanceled`).

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

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

### exception

```rust
fn exception(self: &Self) -> Option<ObservableError>
```

The error of a faulted task (`Exception`, unwrapped from its `AggregateException`).

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

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

### result

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

The outcome of an ended task: the result, the error of a faulted task, or a
`TaskCanceledError` (`Result`, `GetAwaiter().GetResult()`).
## Panics
When the task has not ended: upstream blocks, which would deadlock the only thread.

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

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

### continue_with

```rust
fn continue_with(self: &Self, continuation: impl FnOnce(&Task<T>) -> () + 'static) -> Option<ContinuationId>
```

Runs `continuation` when the task ends, synchronously on the thread that ends it, or at once
when it has ended (`ContinueWith` with `TaskContinuationOptions.ExecuteSynchronously`). The
id removes a continuation that has not run (`remove_continuation`,
the cancellation token of `ContinueWith`); `None` when it ran at once.

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

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

### remove_continuation

```rust
fn remove_continuation(self: &Self, id: ContinuationId) -> 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/threading/tasks/task.rs#L230)

## 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`
- `Debug`
- `Future`
- `From<Task<T>>`
- `From<Receiver<Result<T, Rc<dyn Error>>>>`

## Availability

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