Skip to content

Commit

Permalink
Merge pull request #10 from Edujugon/dev
Browse files Browse the repository at this point in the history
add constants
  • Loading branch information
Edujugon authored Apr 17, 2023
2 parents 1cc333c + 6dc4710 commit 44343e0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-parallelizer",
"version": "2.0.0",
"version": "2.1.1",
"description": "A NodeJS package for running code in parallel. Initially created to provide multiprocessing in an AWS Lambda function, but it can be used in any NodeJS environment.",
"main": "src/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/child-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ChildProcess {
async _processBatchesInForks(batches) {
const batchesCount = batches.length;
const childResponses = {
childResponses: [],
responses: [],
failures: []
};

Expand Down Expand Up @@ -145,7 +145,7 @@ class ChildProcess {
})
childResponses.failures.push(errorMessage);
} else if (status == 'SUCCESS') {
childResponses.childResponses.push(reponse);
childResponses.responses.push(reponse);
}

if (++responsesReceived == batchesCount) {
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const WorkerThreads = require("./worker-thread");

const PARALLELIZER_CHILD = 'child-process';
const PARALLELIZER_THREADS = 'worker-threads';

class Parallelizer {
constructor(params) {
const parallelizer = params.type;
Expand All @@ -14,4 +15,4 @@ class Parallelizer {
}
}
}
module.exports = { ChildProcess, WorkerThreads, Parallelizer };
module.exports = { ChildProcess, WorkerThreads, Parallelizer, PARALLELIZER_CHILD, PARALLELIZER_THREADS };
8 changes: 4 additions & 4 deletions src/worker-thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ class WorkerThreads {
await new Promise((resolve, reject) => {
for (let id = 0; id < batchesCount; id++) {
const worker = new Worker(this.tmpPath, { workerData: { id, batch: batches[id] } });
worker.on('error', reject);
worker.on('exit', (code) => {
worker.on('error', (error) => {
logger({
message: `Worker Thread #${id} exited with code: ${code}`,
message: `Thread #${id} error message: ${error.message}`,
params: {
thread_id: id,
exit_code: code
error_message: error.message
},
debug: this.debug
})
threadResponses.failures.push(error.message);

// In case a thread exists without sending a message.
if (++responsesReceived == batchesCount) {
Expand Down

0 comments on commit 44343e0

Please sign in to comment.