FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    oneshot

    module · ferroui-system · v0.5.0

    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 makes the two ends. The Sender sends one value (Sender::send, which consumes it); dropping it without sending cancels the channel, and the Receiver ends with 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: the Task of the source, as the asynchronous forms of the reactive libraries take it.

    View source

    Contents

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.