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