rl[Symbol.asyncIterator]()


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

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

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

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

async function processLineByLine() {
  const rl = readline.createInterface({
    // ...
  });

  for await (const line of rl) {
    // readline 输入中的每一行将会在此处作为 `line`。
  }
}

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.

Create an AsyncIterator object that iterates through each line in the input stream as a string. This method allows asynchronous iteration of readline.Interface objects through for await...of loops.

Errors in the input stream are not forwarded.

If the loop is terminated with break, throw, or return, rl.close() will be called. In other words, iterating over a readline.Interface will always consume the input stream fully.

Performance is not on par with the traditional 'line' event API. Use 'line' instead for performance-sensitive applications.

async function processLineByLine() {
  const rl = readline.createInterface({
    // ...
  });

  for await (const line of rl) {
    // Each line in the readline input will be successively available here as
    // `line`.
  }
}

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.