Skip to content

Commit

Permalink
fix: build hang (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic authored and evilebottnawi committed Dec 20, 2018
1 parent f564c1c commit fa02b60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/WorkerPool.js
Expand Up @@ -93,15 +93,17 @@ class PoolWorker {
}

writeJson(data) {
const lengthBuffer = new Buffer(4);
const messageBuffer = new Buffer(JSON.stringify(data), 'utf-8');
const lengthBuffer = Buffer.alloc(4);
const messageBuffer = Buffer.from(JSON.stringify(data), 'utf-8');
lengthBuffer.writeInt32BE(messageBuffer.length, 0);
this.writePipe.write(lengthBuffer);
this.writePipe.write(messageBuffer);
}

writeEnd() {
this.writePipe.write(Buffer.alloc(0));
const lengthBuffer = Buffer.alloc(4);
lengthBuffer.writeInt32BE(0, 0);
this.writePipe.write(lengthBuffer);
}

readNextMessage() {
Expand Down Expand Up @@ -261,26 +263,26 @@ export default class WorkerPool {
this.setupLifeCycle();
}

terminate() {
terminate(force) {
if (!this.terminated) {
this.terminated = true;

this.poolQueue.kill();
this.disposeWorkers();
this.disposeWorkers(force);
}
}

setupLifeCycle() {
process.on('SIGTERM', () => {
this.terminate();
this.terminate(true);
});

process.on('SIGINT', () => {
this.terminate();
this.terminate(true);
});

process.on('exit', () => {
this.terminate();
this.terminate(true);
});
}

Expand Down Expand Up @@ -332,8 +334,8 @@ export default class WorkerPool {
}
}

disposeWorkers() {
if (this.activeJobs === 0) {
disposeWorkers(force) {
if (this.activeJobs === 0 || force) {
for (const worker of this.workers) {
worker.dispose();
}
Expand Down
3 changes: 1 addition & 2 deletions src/worker.js
Expand Up @@ -55,7 +55,6 @@ function writePipeUncork() {

function terminateRead() {
terminated = true;
this.writePipe.write(Buffer.alloc(0));
readPipe.removeAllListeners();
}

Expand Down Expand Up @@ -167,7 +166,7 @@ const queue = asyncQueue(({ id, data }, taskCallback) => {
};
}
if (typeof item === 'string') {
const stringBuffer = new Buffer(item, 'utf-8');
const stringBuffer = Buffer.from(item, 'utf-8');
buffersToSend.push(stringBuffer);
return {
buffer: true,
Expand Down

0 comments on commit fa02b60

Please sign in to comment.