• 返回: {AsyncIterator}

    创建一个 AsyncIterator 对象,该对象以字符串形式迭代输入流中的每一行。 这个方法允许 readline.Interface 对象使用 for await...of 循环的异步迭代。

    输入流中的错误不会被转发。

    如果循环以 breakthrowreturn 终止,则 [rl.close()] 将会被调用。 换句话说,对 readline.Interface 的迭代将会始终完全消费输入流。

    性能比不上传统的 'line' 事件的 API。 对于性能敏感的应用程序,请使用 'line'

    1. async function processLineByLine() {
    2. const rl = readline.createInterface({
    3. // ...
    4. });
    5. for await (const line of rl) {
    6. // readline 输入中的每一行将会在此处作为 `line`。
    7. }
    8. }

    readline.createInterface() will start to consume the input stream once invoked. Having asynchronous operations between interface creation and asynchronous iteration may result in missed lines.