FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    Shared

    struct · ferroui-system · v0.5.0

    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

    Members

    channel

    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

    ready

    fn ready(value: T) -> Self
    

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

    Source

    from_outcome

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

    A Shared that has ended with outcome.

    Source

    is_finished

    fn is_finished(self: &Self) -> bool
    

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

    Source

    on_finished

    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

    remove_on_finished

    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

    abort

    fn abort(self: &Self)
    

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

    Source

    ptr_eq

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

    Whether two handles are of the same outcome.

    Source

    outcome

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

    A copy of the outcome when it has ended.

    Source

    flatten

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

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

    Source

    result

    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

    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.