Skip to content

Commit b360429

Browse files
committed
code_style: more safe code for ReadToEndAsync
1 parent b3c2441 commit b360429

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎src/Commands/Command.cs‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,18 @@ protected async Task<Result> ReadToEndAsync()
147147
return Result.Failed(e.Message);
148148
}
149149

150-
var rs = new Result() { IsSuccess = true };
151-
rs.StdOut = await proc.StandardOutput.ReadToEndAsync(CancellationToken).ConfigureAwait(false);
152-
rs.StdErr = await proc.StandardError.ReadToEndAsync(CancellationToken).ConfigureAwait(false);
153-
await proc.WaitForExitAsync(CancellationToken).ConfigureAwait(false);
150+
var stdOutTask = proc.StandardOutput.ReadToEndAsync(CancellationToken);
151+
var stdErrTask = proc.StandardError.ReadToEndAsync(CancellationToken);
152+
var waitForExitTask = proc.WaitForExitAsync(CancellationToken);
154153

155-
rs.IsSuccess = proc.ExitCode == 0;
156-
return rs;
154+
await Task.WhenAll(stdOutTask, stdErrTask, waitForExitTask).ConfigureAwait(false);
155+
156+
return new Result
157+
{
158+
IsSuccess = proc.ExitCode == 0,
159+
StdOut = await stdOutTask.ConfigureAwait(false),
160+
StdErr = await stdErrTask.ConfigureAwait(false)
161+
};
157162
}
158163

159164
protected ProcessStartInfo CreateGitStartInfo(bool redirect)

0 commit comments

Comments
 (0)