public static IPhaseResult <TMapped> Map <TResult, TMapped>( this IPhaseResult <TResult> source, Func <TResult, TMapped> onFinalValue) { return(source switch { Finished <TResult> finished => onFinalValue(finished.Value).AsFinished(), Cancelled <TResult> => PhaseResult.NeedsRetry <TMapped>(), NeedsRetry <TResult> => PhaseResult.NeedsRetry <TMapped>(), _ => throw new Exception() });
public static async Task <IPhaseResult <TResult> > HandlePhase <TResult>( PhaseMethod <TResult> logic) { while (true) { switch (await logic.Invoke()) { case Finished <TResult> finished: return(finished); case Cancelled <TResult> : return(PhaseResult.NeedsRetry <TResult>()); } } }