cluster-rpc.js/process/worker.js

22 lines
592 B
JavaScript
Raw Permalink Normal View History

2016-09-08 22:23:40 +00:00
'use strict';
2018-04-21 01:13:48 +00:00
module.exports.create = function (process, prefixes) {
if (prefixes.debug) { console.log('[cluster-rpc] worker created'); }
2016-09-08 22:23:40 +00:00
var w = new (require('events').EventEmitter)();
process.on('message', function (data) {
w.emit('message', data);
});
w.send = function (data) {
process.send(data);
};
2018-04-21 01:13:48 +00:00
// if this were a web / unix socket there would be a 'connection' event
// emulating this is useful since the worker may create its cluster rpc
// at any time, (which means it may miss the 'fork' event)
w.send({ type: prefixes.connect });
2016-09-08 22:23:40 +00:00
return w;
};