22 lines
592 B
JavaScript
Raw Normal View History

2016-09-08 16:23:40 -06:00
'use strict';
2018-04-20 19:13:48 -06:00
module.exports.create = function (process, prefixes) {
if (prefixes.debug) { console.log('[cluster-rpc] worker created'); }
2016-09-08 16:23:40 -06: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-20 19:13:48 -06: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 16:23:40 -06:00
return w;
};