30 lines
591 B
JavaScript
30 lines
591 B
JavaScript
'use strict';
|
|
|
|
module.exports.create = function () {
|
|
var m = new (require('events').EventEmitter)();
|
|
|
|
m.addWorker = function (worker) {
|
|
m._workers = [];
|
|
|
|
var w = new (require('events').EventEmitter)();
|
|
|
|
worker.on('online', function () {
|
|
//console.log('debug mw: worker is up')
|
|
m.emit('connection', w);
|
|
});
|
|
|
|
worker.on('message', function (data) {
|
|
//console.log('debug mw: worker sends message', data)
|
|
w.emit('message', data);
|
|
});
|
|
|
|
w.send = function (data) {
|
|
worker.send(data);
|
|
};
|
|
|
|
m._workers.push(w);
|
|
};
|
|
|
|
return m;
|
|
};
|