所以我想在同一个readline中请求来自用户的多个输入。问题,并想把它存储到不同的变量中,但我面临的问题是,我不知道怎么做。
import * as readline from 'node:readline';
function askQuestion(query) {
const io = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
return new Promise(resolve => io.question(query, ans => {
resolve(ans);
}));
}
let numRows;
let numCols;
let winLength;
numRows = await askQuestion("Please enter the rows number ");
numCols = await askQuestion("Please enter the columns number ");
winLength = await askQuestion("Please enter the win length ");
numRows, numCols, winLength = await askQuestion(`Please enter${numRows}x${numCols} = ${winLength}`);
我想这样做,但这是不工作。
我面临的另一件事是,它问了很多问题后,我得到了内存泄漏错误在终端
(node:7220) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [ReadStream]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
谁能解决这个内存泄漏错误?
为什么不关闭Readline?
io.close();
resolve(ans);