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

Document and test async iterator helpers #1001

Open
ehmicky opened this issue Apr 30, 2024 · 0 comments
Open

Document and test async iterator helpers #1001

ehmicky opened this issue Apr 30, 2024 · 0 comments

Comments

@ehmicky
Copy link
Collaborator

ehmicky commented Apr 30, 2024

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant