diff --git a/doc/api/readline.md b/doc/api/readline.md index a2a4adf3093a9a..0f00ac5af5a2e3 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -306,6 +306,38 @@ rl.write(null, { ctrl: true, name: 'u' }); The `rl.write()` method will write the data to the `readline` `Interface`'s `input` *as if it were provided by the user*. +### rl[@@asyncIterator] + + +> Stability: 1 - Experimental + +Returns an [AsyncIterator][async-iterator] to fully consume the stream. + +```js +const readline = require('readline'); +const fs = require('fs'); + +async function processLineByLine(readable) { + readable.setEncoding('utf8'); + const rli = readline.createInterface({ + input: readable, + crlfDelay: Infinity + }); + + for await (const line of rli) { + console.log(line); + } +} + +processLineByLine(fs.createReadStream('file')).catch(console.error); +``` + +If the loop terminates with a `break` or a `throw`, the stream will be +destroyed. In other terms, iterating over a stream will consume the stream +fully. + ## readline.clearLine(stream, dir)