I want to implement multiple threads to execute the code separately, but I will use rl.question to input some information through the command line. According to my thinking, when each thread executes rl.question, it will wait for my input. If other threads also execute rl.question, it should be listed at the back and be called after I finish typing the previous rl.question. The actual effect is not like this.

I do this in a child thread

const { stdin: input, stdout: output } = require('node:process');
const rl = readline.createInterface({
  input,
  output,
});

rl.question("请输入你的名字:", (name) => {
      parentPort.postMessage(`你好,${name}!`);
      rl.close();
    });
0

There are 0 best solutions below