ResTryAsync Method

(async version) When IsOk executes action() in a try-catch block: returns back itself if the process succeeds; Err if it throws. Does not do anything and returns back itself when IsErr.
C#
static Res TryLogin() { .. }
static void ClearSessionHistory() { /*risky function, might throw!*/ }

var result = TryLogin().Try(ClearSessionHistory);
// the result will be:
// - Err if TryLogin returns Err, in which case ClearSessionHistory is never called;
// - Ok if TryLogin returns Ok; and ClearSessionHistory call succeeds without an exception;
// - Err if TryLogin returns Ok, but ClearSessionHistory throws an exception.

Definition

Namespace: Orx.Fun.Result
Assembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
C#
public Task<Res> TryAsync(
	Func<Task> action,
	string name = ""
)

Parameters

action  FuncTask
Action to be executed in a try-catcy block only if this IsOk.
name  String  (Optional)
Name of the map action; to be appended to the error messages if the action throws. Omitting the argument will automatically be filled with the action's expression in the caller side.

Return Value

TaskRes

See Also