# oneshot

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

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

```rust
module oneshot
```

A value sent once to the code that waits for it: the port of `TaskCompletionSource` (step A3
of phase C4 of #423, docs/idiomatic-rust-async.md, section 3.3).

[`channel`](/docs/0.5.0/api/ferroui-system/task/oneshot/function-channel/) makes the two ends. The [`Sender`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-sender/) sends one value (`Sender::send`, which
consumes it); dropping it without sending cancels the channel, and the [`Receiver`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-receiver/) ends with
[`Canceled`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-canceled/) instead of waiting for ever. The receiver is a future of the value, and can also
be asked without waiting (`Receiver::try_recv`) or waited for by blocking the thread
(`Receiver::blocking_recv`, `Receiver::recv_timeout`). `Receiver::shared` makes a
receiver that several waiters clone, each getting a copy of the value.

The channel has no thread of its own: either end may be used on any thread (both are `Send`
and `Sync` when the value is `Send`), and where the code that awaits the receiver continues is
decided by the waker of its task. Sending wakes that waker inside the call that sends; the
executor of the task decides whether the task runs at once (a task of the queue of the same
thread) or later (a dispatcher job, the queue of another thread).

In terms of the `TaskCompletionSource` of .NET: `SetResult` is `send(value)`, `SetException`
is `send(Err(error))` on a channel of a `Result`, `SetCanceled` is dropping the sender, and the
`TrySet` forms are `send`, which gives the value back when the receiver is gone. The `flatten`
of a receiver of a `Result<T, ObservableError>` is a future of that result, with a dropped
sender as the error [`Canceled`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-canceled/): the `Task` of the source, as the asynchronous forms of the
reactive libraries take it.

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

## Contents

- [`Canceled`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-canceled/) — struct
- [`channel`](/docs/0.5.0/api/ferroui-system/task/oneshot/function-channel/) — function
- [`Sender`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-sender/) — struct
- [`Receiver`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-receiver/) — struct
- [`SharedReceiver`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-sharedreceiver/) — struct

## Availability

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