Skip to content

Commit 3c7290d

Browse files
committed
Add WaitAsync
1 parent 177c38c commit 3c7290d

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ await foreach (string item in ProcessX.StartAsync("dotnet --info"))
4949
}
5050

5151
// receive string result from stdout.
52-
var branch = await ProcessX.StartAsync("git branch --show-current").FirstAsync();
52+
var version = await ProcessX.StartAsync("dotnet --version").FirstAsync();
5353

5454
// receive buffered result(similar as WaitForExit).
5555
string[] result = await ProcessX.StartAsync("dotnet --info").ToTask();
5656

5757
// like the shell exec, write all data to console.
5858
await ProcessX.StartAsync("dotnet --info").WriteLineAllAsync();
5959

60+
// consume all result and wait complete asynchronously(useful to use no result process).
61+
await ProcessX.StartAsync("cmd /c mkdir foo").WaitAsync();
62+
6063
// when ExitCode is not 0 or StandardError is exists, throws ProcessErrorException
6164
try
6265
{
@@ -269,6 +272,9 @@ FirstAsync(CancellationToken cancellationToken = default)
269272
// return Task<string?>
270273
FirstOrDefaultAsync(CancellationToken cancellationToken = default)
271274

275+
// return Task
276+
WaitAsync(CancellationToken cancellationToken = default)
277+
272278
// return Task<string[]>
273279
ToTask(CancellationToken cancellationToken = default)
274280

sandbox/ConsoleApp/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010

1111

12-
var s = await ProcessX.StartAsync("git branch --show-current").FirstAsync();
13-
System.Console.WriteLine(s);
12+
await ProcessX.StartAsync("cmd /c mkdir foo").WaitAsync();
13+
14+
return;
15+
1416

1517

1618
// `await string` execute process like shell

src/ProcessX/ProcessAsyncEnumerable.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ public IAsyncEnumerator<string> GetAsyncEnumerator(CancellationToken cancellatio
2424
return new ProcessAsyncEnumerator(process, channel, cancellationToken);
2525
}
2626

27+
/// <summary>
28+
/// Consume all result and wait complete asynchronously.
29+
/// </summary>
30+
public async Task WaitAsync(CancellationToken cancellationToken = default)
31+
{
32+
await foreach (var _ in this.WithCancellation(cancellationToken).ConfigureAwait(false))
33+
{
34+
}
35+
}
36+
2737
/// <summary>
2838
/// Returning first value. If does not return any data, returns empty string.
2939
/// </summary>

0 commit comments

Comments
 (0)