workers: minor.
This commit is contained in:
parent
498264b417
commit
7530359b55
@ -146,9 +146,6 @@ Master.prototype.listen = function listen() {
|
|||||||
|
|
||||||
this.listening = true;
|
this.listening = true;
|
||||||
|
|
||||||
util.log = this.log.bind(this);
|
|
||||||
util.error = util.log;
|
|
||||||
|
|
||||||
this.on('error', (err) => {
|
this.on('error', (err) => {
|
||||||
this.send(new packets.ErrorPacket(err));
|
this.send(new packets.ErrorPacket(err));
|
||||||
});
|
});
|
||||||
@ -177,7 +174,7 @@ Master.prototype.handlePacket = function handlePacket(packet) {
|
|||||||
break;
|
break;
|
||||||
case packets.types.EVENT:
|
case packets.types.EVENT:
|
||||||
this.emit('event', packet.items);
|
this.emit('event', packet.items);
|
||||||
this.emit.apply(this, packet.items);
|
this.emit(...packet.items);
|
||||||
break;
|
break;
|
||||||
case packets.types.ERROR:
|
case packets.types.ERROR:
|
||||||
this.emit('error', packet.error);
|
this.emit('error', packet.error);
|
||||||
|
|||||||
@ -8,6 +8,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Master = require('./master');
|
const Master = require('./master');
|
||||||
|
const util = require('../utils/util');
|
||||||
const server = new Master();
|
const server = new Master();
|
||||||
|
|
||||||
|
util.log = server.log.bind(server);
|
||||||
|
util.error = util.log;
|
||||||
|
|
||||||
server.listen();
|
server.listen();
|
||||||
|
|||||||
@ -124,7 +124,7 @@ WorkerPool.prototype.spawn = function spawn(id) {
|
|||||||
|
|
||||||
child.on('event', (items) => {
|
child.on('event', (items) => {
|
||||||
this.emit('event', items, child);
|
this.emit('event', items, child);
|
||||||
this.emit.apply(this, items);
|
this.emit(...items);
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on('log', (text) => {
|
child.on('log', (text) => {
|
||||||
@ -186,11 +186,12 @@ WorkerPool.prototype.destroy = function destroy() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
WorkerPool.prototype.execute = function execute(packet, timeout) {
|
WorkerPool.prototype.execute = function execute(packet, timeout) {
|
||||||
let result, child;
|
let child;
|
||||||
|
|
||||||
if (!this.enabled || !Child.hasSupport()) {
|
if (!this.enabled || !Child.hasSupport()) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
|
let result;
|
||||||
try {
|
try {
|
||||||
result = jobs.handle(packet);
|
result = jobs.handle(packet);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -447,8 +448,8 @@ Worker.prototype.listen = function listen() {
|
|||||||
Worker.prototype.handlePacket = function handlePacket(packet) {
|
Worker.prototype.handlePacket = function handlePacket(packet) {
|
||||||
switch (packet.cmd) {
|
switch (packet.cmd) {
|
||||||
case packets.types.EVENT:
|
case packets.types.EVENT:
|
||||||
this.emit.apply(this, packet.items);
|
|
||||||
this.emit('event', packet.items);
|
this.emit('event', packet.items);
|
||||||
|
this.emit(...packet.items);
|
||||||
break;
|
break;
|
||||||
case packets.types.LOG:
|
case packets.types.LOG:
|
||||||
this.emit('log', packet.text);
|
this.emit('log', packet.text);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user