Skip to content

Commit

Permalink
Merge pull request #14 from Edujugon/dev
Browse files Browse the repository at this point in the history
Update code examples
  • Loading branch information
Edujugon authored May 8, 2023
2 parents bef3afb + 40e2521 commit c158d41
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 19 deletions.
180 changes: 180 additions & 0 deletions examples/basic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"license": "ISC",
"dependencies": {
"axios": "^1.4.0",
"node-parallelizer": "^2.1.1"
"node-parallelizer": "^3.0.0"
}
}
12 changes: 8 additions & 4 deletions examples/basic/src/lambda-parallelizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ const { Parallelizer, PARALLELIZER_CHILD, PARALLELIZER_THREADS } = require("node
const parallelizerType = process.env.PARALLELIZER_TYPE || PARALLELIZER_CHILD;
const parallelizerDebug = process.env.PARALLELIZER_DEBUG_MODE_ENABLED === 'true' ? true : false;

const parallelizer = new Parallelizer({ type: parallelizerType, debug: parallelizerDebug, parallelizationPerCPU: process.env.PROCESSESPERCPU || 1 });
const parallelizer = new Parallelizer({
type: parallelizerType,
debug: parallelizerDebug,
parallelizationPerCPU: process.env.PROCESSESPERCPU || 1,
filePath: "/var/task/src/parallelizer-code.js",
processBatchFunctionName: 'batchProcessor'
});

// Creates child processes based with your custom code.
parallelizer.parallelizerFunction({filePath: "/var/task/src/parallelizer-code.js", processBatchFunctionName: 'batchProcessor' });

exports.handler = async (event) => {

const batch = [...Array(event.number).keys()];

// Run batch in parallel
const responses = await parallelizer.runBatch(batch);
const responses = await parallelizer.run(batch);

console.log(JSON.stringify(responses));
};
14 changes: 7 additions & 7 deletions examples/with-bundler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/with-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"axios": "^1.4.0",
"esbuild": "^0.17.18",
"node-parallelizer": "^2.1.1"
"node-parallelizer": "^3.0.0"
},
"devDependencies": {
"serverless-esbuild": "^1.43.0",
Expand Down
13 changes: 8 additions & 5 deletions examples/with-bundler/src/lambda-parallelizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ const { Parallelizer, PARALLELIZER_CHILD, PARALLELIZER_THREADS } = require("node
const parallelizerType = process.env.PARALLELIZER_TYPE || PARALLELIZER_CHILD;
const parallelizerDebug = process.env.PARALLELIZER_DEBUG_MODE_ENABLED === 'true' ? true : false;

const parallelizer = new Parallelizer({ type: parallelizerType, debug: parallelizerDebug, parallelizationPerCPU: process.env.PROCESSESPERCPU || 1 });

// Creates child processes based with your custom code.
parallelizer.parallelizerFunction({filePath: "/var/task/src/parallelizer-code-min.js", processBatchFunctionName: 'batchProcessor' });
const parallelizer = new Parallelizer({
type: parallelizerType,
debug: parallelizerDebug,
parallelizationPerCPU: process.env.PROCESSESPERCPU || 1,
filePath: "/var/task/src/parallelizer-code-min.js",
processBatchFunctionName: 'batchProcessor'
});

exports.handler = async (event) => {

const batch = [...Array(event.number).keys()];

// Run batch in parallel
const responses = await parallelizer.runBatch(batch);
const responses = await parallelizer.run(batch);

console.log(JSON.stringify(responses));
};
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": "3.0.0",
"version": "3.0.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

0 comments on commit c158d41

Please sign in to comment.