Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes subprocesses async iterable.
A
subprocess.iterable(options)
method is also available to pass options. The options are the same assubprocess.readable()
:{from?: string, binary?: boolean, preserveNewlines?: boolean}
.Advantages over
subprocess.readable()
Since streams are async iterable, this is similar to:
However, it is better than
subprocess.readable()
when the user just wants to iterate over output lines:Symbol.asyncIterator
, which results in a simpler syntax (first example above).subprocess.readable()
(since streams can be used in other ways), which means the user must explicitly opt-in to line iteration usingsubprocess.readable({binary: false, preserveNewlines: false})
.subprocess.readable()
actually adds a few additional layers. First, a stream is created, with some state that must be synced with the subprocess (which is not simple). Then, that stream consumes the underlying async iterable in its.read()
method. Then, theReadable
iteration calls.read()
repeatedly, in a different async iterable.subprocess.stdout
(stream) ->on(stream, 'data')
(iterable) ->subprocess.readable()
(stream) ->Readable.iterator()
(iterable).Advantages over iterating over
subprocess.stdout
Just like
subprocess.readable()
,subprocess.iterable()
is better than just iterating oversubprocess.stdout
.Because:
subprocess.stdout
failures, which rarely happens)Difference with Execa transforms
Unlike Execa transforms:
subprocess.stdout
, which can be either good or bad, depending on the use case