Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Allow objects to be passed as a parameter on the worker-pool method #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/worker-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ module.exports = function(options) {

var workers = farm(options, require.resolve('./worker'));

return function(fn) {
return function(fn, optns) {
var code = fn.toString();
var params = JSON.stringify({
options: optns,
fn: code
});
return function(cb) {
workers(code, cb);
workers(params, cb);
};
};
};
6 changes: 4 additions & 2 deletions lib/worker-pool/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function parseFn(str) {
return cache[str];
}

module.exports = function(code, cb) {
var fn = parseFn(code);
module.exports = function(optns, cb) {
optns = JSON.parse(optns);
var code = optns.fn;
var fn = parseFn(code).bind(optns.options);
asyncDone(fn, cb);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spawn-task-experiment",
"version": "0.1.4",
"version": "0.1.5",
"description": "Tests how fast it is to run gulp tasks in child processes",
"main": "index.js",
"scripts": {
Expand Down