Skip to content

Document and test async iterator helpers #1001

Description

@ehmicky

Synchronous iterator helpers just landed in Node 22. Async iterator helpers are currently a stage 2 ES proposal. Once they land in Node, we should add some tests, and document how to use them with Execa.

They could be quite nice to use with Execa. For example:

for await (const line of execa`npm run build`.iterable().map(line => line.toUpperCase()) {
  // ...
}
for await (const line of execa`npm run build`.iterable().filter(line => !line.includes('secret')) {
  // ...
}
// First 3 lines of output only
for await (const line of execa`npm run build`.iterable().take(3)) {
  // `return` or `break` inside this loop will still await for the subprocess completion, which is good
  // ...
}

Note: iterable.some(), iterable.every() and iterable.find() would also be useful to get a quick return value while the subprocess is still running. However, those won't wait for the subprocess to complete, so the user would need to call await subprocess, unlike the other iterator methods.

Also, those could be used with getEachMessage().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions