因此,我想询问来自同一个readline.question中的用户的多个输入,并将其存储到不同的变量中,但我面临的问题是,我不知道如何做到这一点。码
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)谁能解决这个内存泄漏错误?
发布于 2022-11-23 01:37:17
为什么不关闭Readline呢?
io.close();
resolve(ans);https://stackoverflow.com/questions/74540822
复制相似问题