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>.
Members
channelreadyfrom_outcomeis_finishedon_finishedremove_on_finishedabortptr_eqoutcomeflattenresult
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).
ready
fn ready(value: T) -> Self
A Shared that has ended with value (Task.FromResult).
from_outcome
fn from_outcome(outcome: Result<T, JoinError>) -> Self
A Shared that has ended with outcome.
is_finished
fn is_finished(self: &Self) -> bool
Whether it has ended, and its observers have been told.
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.
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.
abort
fn abort(self: &Self)
Aborts the task (see JoinHandle::abort); nothing for a
Shared that no task ends.
ptr_eq
fn ptr_eq(this: &Self, other: &Self) -> bool
Whether two handles are of the same outcome.
outcome
fn outcome(self: &Self) -> Option<Result<T, JoinError>>
A copy of the outcome when it has ended.
flatten
fn flatten(self: Self) -> Flatten<T>
A future of the outcome as one result (Flatten).
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.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyIntoFutureToOwnedCloneFutureDebugFrom<Task<T>>
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.