public async Task <T> Trigger() { if (!Enabled) { Logger.Error(GetType(), "Not really running remote action because action is disabled"); throw new Exception("trying to trigger disabled action"); } Logger.Debug(GetType(), "Running remote action"); ResultHolder <T> resultAsHolder; try { StartedExecution(); var result = await _remoteAction(); resultAsHolder = ResultHolder <T> .CreateSuccess(result); await ExecOnUiThread.Exec(() => ActionExecuted?.Invoke(resultAsHolder)); return(result); } catch (Exception ex) { resultAsHolder = ResultHolder <T> .CreateFailure(ex.Message, ex); await ExecOnUiThread.Exec(() => ActionExecuted?.Invoke(resultAsHolder)); throw; } finally { Logger.Debug(GetType(), "Remote action ended"); EndedExecution(); } }
public void Add <T>(Func <Task <T> > oper, Func <T, Task> forwardOutcomeOrNull) { _operations.Add(async() => { var outcome = await oper(); if (forwardOutcomeOrNull != null) { await ExecOnUiThread.ExecAsync(() => forwardOutcomeOrNull(outcome)); } return(Unit.Instance); }); }
// // one param // public void Add <InpT, OutT>( Func <InpT> input, Func <InpT, Task <OutT> > oper, Action <OutT> forwardOutcomeOrNull = null) { _operations.Add(async() => { var outcome = await oper(input()); if (forwardOutcomeOrNull != null) { await ExecOnUiThread.Exec(() => forwardOutcomeOrNull(outcome)); } return(Unit.Instance); }); }
public void Add <InpT1, InpT2, OutT>( Func <Tuple <InpT1, InpT2> > input, Func <InpT1, InpT2, Task <OutT> > oper, Func <OutT, Task> forwardOutcomeOrNull) { _operations.Add(async() => { var pars = input(); var outcome = await oper(pars.Item1, pars.Item2); if (forwardOutcomeOrNull != null) { await ExecOnUiThread.ExecAsync(() => forwardOutcomeOrNull(outcome)); } return(Unit.Instance); }); }