Class MutationState<TData, TProgress>
- Namespace
- Fetchling.Core
- Assembly
- Fetchling.Core.dll
An immutable snapshot of a progress-reporting mutation's current state. Identical to MutationState<TData> plus Progress, the latest value the mutator reported. Use the static factory methods to create instances.
public sealed record MutationState<TData, TProgress> : IEquatable<MutationState<TData, TProgress>>
Type Parameters
TDataThe type of data returned by the mutation on success.
TProgressThe type of the progress values the mutator reports.
- Inheritance
-
MutationState<TData, TProgress>
- Implements
-
IEquatable<MutationState<TData, TProgress>>
- Inherited Members
Properties
CurrentData
The data returned by the most recent successful execution.
null when the mutation has not yet succeeded.
public TData? CurrentData { get; }
Property Value
- TData
Error
The exception from the most recent failed execution. null when not in a failure state.
public Exception? Error { get; }
Property Value
HasData
true when the mutation has succeeded and CurrentData is available.
public bool HasData { get; }
Property Value
HasError
true when Error is not null.
public bool HasError { get; }
Property Value
IsFailure
public bool IsFailure { get; }
Property Value
IsIdle
public bool IsIdle { get; }
Property Value
IsRunning
public bool IsRunning { get; }
Property Value
IsSuccess
public bool IsSuccess { get; }
Property Value
Progress
The latest value the mutator reported through its IProgress<T>.
default before the first report of an attempt — it resets at the start of every retry,
because a retried mutator starts over. Success and
Failure keep the last reported value (so a UI can show
"failed at 60 %"); Idle — including after a cancellation — clears it.
public TProgress? Progress { get; }
Property Value
- TProgress
Status
The current lifecycle status of the mutation.
public MutationStatus Status { get; }
Property Value
Methods
CreateFailure(Exception, TProgress?)
Creates a Failure state with the given error.
public static MutationState<TData, TProgress> CreateFailure(Exception error, TProgress? progress)
Parameters
errorExceptionThe exception thrown by the mutation.
progressTProgressThe last progress the mutator reported before it threw.
Returns
- MutationState<TData, TProgress>
CreateIdle()
Creates an Idle state with no progress.
public static MutationState<TData, TProgress> CreateIdle()
Returns
- MutationState<TData, TProgress>
CreateRunning(TProgress?)
Creates a Running state carrying the latest reported progress.
public static MutationState<TData, TProgress> CreateRunning(TProgress? progress)
Parameters
progressTProgressThe latest reported progress;
defaultbefore the first report.
Returns
- MutationState<TData, TProgress>
CreateSuccess(TData, TProgress?)
Creates a Success state with the returned data.
public static MutationState<TData, TProgress> CreateSuccess(TData data, TProgress? progress)
Parameters
dataTDataThe data returned by the mutation.
progressTProgressThe last progress the mutator reported before it returned.
Returns
- MutationState<TData, TProgress>