以下是代码:
{}
我期待输出为:
import fs from 'fs';
import readline from 'readline';
let rl;
rl = readline.createInterface({
input: fs.createReadStream(__dirname + '/allCountries.txt')
});
rl.on('line', (line) => {
rl.pause();
console.log('pause');
// Do something that takes time with the line....
setTimeout(() => {
console.log('resume');
rl.resume();
}, 500);
});
但输出是:
pause
resume
pause
resume
pause
resume
pause
resume
pause
resume
pause
resume
pause
resume
pause
resume
pause
resume
如何强制readline
模块读取一行,暂停并等待读取恢复?