pub struct Task<T> { /* private fields */ }Expand description
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).
Implementations§
Source§impl<T: 'static> Task<T>
impl<T: 'static> Task<T>
Sourcepub fn from_result(result: T) -> Self
pub fn from_result(result: T) -> Self
A task that has ended with result (Task.FromResult).
Sourcepub fn from_exception(error: ObservableError) -> Self
pub fn from_exception(error: ObservableError) -> Self
A task that has ended with error (Task.FromException); a TaskCanceledError makes it
canceled.
Sourcepub fn from_canceled() -> Self
pub fn from_canceled() -> Self
A canceled task (Task.FromCanceled).
Sourcepub fn spawn_local(
future: impl Future<Output = Result<T, ObservableError>> + 'static,
) -> Self
pub 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.
Sourcepub fn status(&self) -> TaskStatus
pub fn status(&self) -> TaskStatus
The state of the task (Status).
Sourcepub fn is_completed(&self) -> bool
pub fn is_completed(&self) -> bool
Whether the task has ended, in any way (IsCompleted).
Sourcepub fn is_completed_successfully(&self) -> bool
pub fn is_completed_successfully(&self) -> bool
Whether the task has ended with a result (IsCompletedSuccessfully).
Sourcepub fn is_faulted(&self) -> bool
pub fn is_faulted(&self) -> bool
Whether the task has ended with an error (IsFaulted).
Sourcepub fn is_canceled(&self) -> bool
pub fn is_canceled(&self) -> bool
Whether the task has been canceled (IsCanceled).
Sourcepub fn exception(&self) -> Option<ObservableError>
pub fn exception(&self) -> Option<ObservableError>
The error of a faulted task (Exception, unwrapped from its AggregateException).
Sourcepub fn result(&self) -> Result<T, ObservableError>where
T: Clone,
pub fn result(&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.
Sourcepub fn continue_with(
&self,
continuation: impl FnOnce(&Task<T>) + 'static,
) -> Option<ContinuationId>
pub fn continue_with( &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.
Sourcepub fn remove_continuation(&self, id: ContinuationId) -> bool
pub fn remove_continuation(&self, id: ContinuationId) -> bool
Removes a continuation that has not run; false when it has run or was removed.