Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

如何理解: `readline.Interface 的迭代将会始终完全消费输入流` ?

http://nodejs.cn/api/readline...

文档写着:

rl[Symbol.asyncIterator]()

这个方法允许 `readline.Interface` 对象使用 `for await...of` 循环的异步迭代。

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

如果循环以 `break`, `throw` 或 `return` 终止,则 [`rl.close()`](http://nodejs.cn/api/readline.html#readline_rl_close) 将会被调用。 换句话说,对 `readline.Interface` 的迭代将会始终完全消费输入流。

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


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

始终完全消费输入流 意思是什么? 意思是会整个读取不是按行读取? 意思是会把整个文件一次性读取完放入内存?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...