Example #1
0
        private async Task<CommandResult<TResult>> InvokeAndWrapAsync<TResult>(AsyncCommand<TResult> command, InformativeCancellationToken ct)
        {
            // Even though we're in a "Return" method, multiple invokes are a bug on the calling
            // side, hence the possible exception here for visibility so the caller can fix.
            EnsureSingleInvoke(command);

            try
            {
                TResult result;
                if (!IsEnabled())
                {
                    result = await command.ExecuteAsync(CancellationToken.None);
                }
                else
                {
                    result = await InvokeAsync(command, ct, OnFailure.Return);
                }
                return new CommandResult<TResult>(result);
            }
            catch (Exception e)
            {
                return new CommandResult<TResult>(default(TResult), e);
            }
        }
Example #2
0
 public Task<CommandResult<TResult>> InvokeReturnAsync<TResult>(AsyncCommand<TResult> command, CancellationToken ct)
 {
     var token = GetCancellationTokenForCommand(ct);
     return InvokeAndWrapAsync(command, token);
 }
Example #3
0
 public Task<CommandResult<TResult>> InvokeReturnAsync<TResult>(AsyncCommand<TResult> command, long timeoutMillis)
 {
     var token = GetCancellationTokenForCommand(command, timeoutMillis);
     return InvokeAndWrapAsync(command, token);
 }