Task
struct · ferroui-system · v0.5.0
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).
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_resultfrom_exceptionfrom_canceledspawn_localidstatusis_completedis_completed_successfullyis_faultedis_canceledexceptionresultcontinue_withremove_continuation
from_result
fn from_result(result: T) -> Self
A task that has ended with result (Task.FromResult).
from_exception
fn from_exception(error: ObservableError) -> Self
A task that has ended with error (Task.FromException); a cancellation (Canceled,
TaskCanceledError) makes it canceled.
from_canceled
fn from_canceled() -> Self
A canceled task (Task.FromCanceled).
spawn_local
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.
id
fn id(self: &Self) -> u64
The identity of the task (Id).
status
fn status(self: &Self) -> TaskStatus
The state of the task (Status).
is_completed
fn is_completed(self: &Self) -> bool
Whether the task has ended, in any way (IsCompleted).
is_completed_successfully
fn is_completed_successfully(self: &Self) -> bool
Whether the task has ended with a result (IsCompletedSuccessfully).
is_faulted
fn is_faulted(self: &Self) -> bool
Whether the task has ended with an error (IsFaulted).
is_canceled
fn is_canceled(self: &Self) -> bool
Whether the task has been canceled (IsCanceled).
exception
fn exception(self: &Self) -> Option<ObservableError>
The error of a faulted task (Exception, unwrapped from its AggregateException).
result
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.
continue_with
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.
remove_continuation
fn remove_continuation(self: &Self, id: ContinuationId) -> bool
Removes a continuation that has not run; false when it has run or was removed.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyIntoFutureToOwnedCloneDebugFutureFrom<Task<T>>From<Receiver<Result<T, Rc<dyn Error>>>>
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.