示例#1
0
    public static async ValueTask WaitForOutput(this XProcess process, Func <string, bool> predicate, int millsecondsTimeout)
    {
        var bufferedOutput = process.GetAndClearBufferedOutput();

        if (predicate(bufferedOutput))
        {
            return;
        }

        var cts = new CancellationTokenSource(millsecondsTimeout);

        await foreach (var output in process.GetOutputAsyncStream().WithCancellation(cts.Token))
        {
            if (predicate(output))
            {
                return;
            }
        }
    }