Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace IProcess.WaitForProcessExitAsync with WaitForExitAsync #10802

Merged
merged 2 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions GitCommands/Git/Executable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GitExtUtils;
using GitUI;
using GitUIPluginInterfaces;
using Microsoft.VisualStudio.Threading;

namespace GitCommands
{
Expand Down Expand Up @@ -220,10 +221,7 @@ public StreamReader StandardError
public Task<int> WaitForExitAsync() => _exitTaskCompletionSource.Task;

/// <inheritdoc />
public Task WaitForProcessExitAsync(CancellationToken token)
{
return _process.WaitForExitAsync(token);
}
public Task<int> WaitForExitAsync(CancellationToken token) => WaitForExitAsync().WithCancellation(token);

/// <inheritdoc />
public int WaitForExit()
Expand Down
9 changes: 3 additions & 6 deletions GitCommands/Git/ExecutableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,13 @@ public static async Task<ExecutionResult> ExecuteAsync(
}
#endif

// Wait for the process to exit (or be cancelled)
await process.WaitForProcessExitAsync(cancellationToken);

// Await the output and exit status
var exitTask = process.WaitForExitAsync();
// Wait for the process to exit (or be cancelled) and for the output
Task<int> exitTask = process.WaitForExitAsync(cancellationToken);
await Task.WhenAll(outputTask, errorTask, exitTask);

var output = outputEncoding.GetString(outputBuffer.GetBuffer(), 0, (int)outputBuffer.Length);
var error = outputEncoding.GetString(errorBuffer.GetBuffer(), 0, (int)errorBuffer.Length);
var exitCode = await process.WaitForExitAsync();
int exitCode = await exitTask;

if (cache is not null && exitCode == 0)
{
Expand Down
10 changes: 4 additions & 6 deletions Plugins/GitUIPluginInterfaces/IProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ public interface IProcess : IDisposable
/// <summary>
/// Returns a task that completes when the process exits, or when this object is disposed.
/// </summary>
/// <returns>A task that yields the process's exit code, or <c>null</c> if this object was disposed before the process exited.</returns>
/// <returns>A task that yields the process's exit code, or throws an exception if this object was disposed before the process exited.</returns>
Task<int> WaitForExitAsync();

/// <summary>
/// Instructs the process component to wait for the associated process to exit, or for the cancellationToken to be cancelled (cancells the process).
/// Note that the exit task must be awaited too.
/// Returns a cancellable task that completes when the process exits, or when this object is disposed.
/// </summary>
/// <param name="token">An optional token to cancel the asynchronous operation.</param>
/// <returns>A task that will complete when the process has exited, cancellation has been requested, or an error occurs.</returns>
Task WaitForProcessExitAsync(CancellationToken token);
/// <returns>A task that yields the process's exit code, or throws an exception if this object was disposed before the process exited.</returns>
Task<int> WaitForExitAsync(CancellationToken token);

/// <summary>
/// Waits for the process to reach an idle state.
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/CommonTestUtils/MockExecutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public Task<int> WaitForExitAsync()
}
}

public Task WaitForProcessExitAsync(CancellationToken token)
public Task<int> WaitForExitAsync(CancellationToken token)
{
return Task.CompletedTask;
return Task.FromResult(0);
}

public void WaitForInputIdle()
Expand Down