Class TaskWithProgress<T>
Represents a task with progress reporting capabilities.
Implements
Namespace: FulcrumFS
Assembly: FulcrumFS.dll
Syntax
public sealed class TaskWithProgress<T> : IAsyncEnumerable<ProgressValue>
Type Parameters
| Name | Description |
|---|---|
| T |
Remarks
If you do not care about progress reporting, you can simply await on this task as you would with a normal Task<TResult>.
If you care about progress reporting, you can use it as an IAsyncEnumerable<T> of ProgressValues via await foreach, and then get the result by a normal await after you're done with the progress reporting. You cannot begin progress reporting if you have already begun awaiting normally (you must begin progress reporting first), nor can you start multiple progress reporting enumerations concurrently. You can, however, run multiple normal awaits concurrently (like with Task<TResult>).
Progress values for each stage are reported in the range [0.0, 1.0], are monotonically increasing, and always include both 0.0 and 1.0 (unless a failure occurs partway through). Progress values are strictly increasing except when only the stage display message changes, in which case a value may be reported that repeats the previous progress fraction with the updated message.
If an exception occurs in the underlying operation and it is not observed by the caller through either GetAwaiter() or
GetAsyncEnumerator(CancellationToken), it will surface as an unobserved task exception like with a normal Task<TResult>. Additionally, each call
to GetAwaiter() is treated like a new task, so if you call that method and do not observe the exception, you could also see an unobserved task
exception for each of those calls. The handling for GetAsyncEnumerator(CancellationToken) is similar in most cases, but if you're manually enumerating, then
ignoring the result of a MoveNextAsync that would throw will not result in an unobserved task exception, and will instead consume the exception.
Methods
| Name | Description |
|---|---|
| AddPostTask(Func<bool, T?, ValueTask>) | Appends the task with the specified task action, which is executed when the task completes. |
| AddPreTask(Func<bool, ValueTask>) | Prepends the task with the specified task action, which is executed before the task begins. |
| CastTo<TNew>(Func<T, ValueTask<TNew>>, bool) | Casts the result of this task to a new type using the specified converter function. |
| ConfigureAwait(bool) | Configures an awaiter for this task. |
| ConfigureAwait(ConfigureAwaitOptions) | Configures an awaiter for this task. |
| GetAsyncEnumerator(CancellationToken) | Exposes an asynchronous enumerator for progress reporting. |
| GetAwaiter() | Creates an awaiter for this task. |