發(fā)現(xiàn)在 Node.js 中進程間通信使用的信號機制與事件機制十分相似(見下方代碼示例),這背后有什么道理嗎?或者一種設計模式?
signal
child.kill('SIGUSR1');
process.on('SIGUSR1', function () {
console.log('Got a SIGUSR1 signal.');
})
event
eventEmitter.emit('event')
eventEmitter.on('event', function () {
console.log('Trigger an event.');
})
走同樣的路,發(fā)現(xiàn)不同的人生