#1001·execa

Document and test async iterator helpers

Author: ehmickyCreated Apr 30, 2024Updated Aug 11, 2026

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:

javascript
for await (const line of execa`npm run build`.iterable().map(line => line.toUpperCase()) {
  // ...
}
javascript
for await (const line of execa`npm run build`.iterable().filter(line => !line.includes('secret')) {
  // ...
}
javascript
// 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().