小编Kie*_*lus的帖子

通过IPC通道从生成的子进程发送错误对象

我启用了父进程和子进程之间的通信,以便按如下方式发送JSON:

儿童:

try {  
  var price1 = parseInt(process.argv[2]);
  if (!price1) {
     throw new Error('Price in calculations.js undefined');
  }
  var result = {
    'timeStamp' : Date(),
    'prices' : { 'player1' : price1, 'player2' : 666}
  };
  process.send(result);
} catch (e) {
  // In case of an error, I get here as expected.
  process.send(e);
}
Run Code Online (Sandbox Code Playgroud)

家长:

var spawn = require('child_process').spawn;
var child = spawn('node', ['calculations.js', 333],  {stdio: [null,null,'pipe','ipc']});
child.on('message', function(data) {    
  if (data instanceof Error) {
    // In case of an error, …
Run Code Online (Sandbox Code Playgroud)

javascript inter-process-communicat node.js

7
推荐指数
1
解决办法
1144
查看次数

流中的条件类型

是否可以根据条件在流中键入变量?像这样的东西:

const type = 'xyz';
const a: (type === 'xyz') ? number : string;
Run Code Online (Sandbox Code Playgroud)

javascript flowtype

6
推荐指数
2
解决办法
1894
查看次数