diff --git a/bin/index.js b/bin/index.js index 5e842f4..c68e5d3 100755 --- a/bin/index.js +++ b/bin/index.js @@ -5,8 +5,9 @@ var path = require('path') var range = require('lodash.range') var pkg = require('../package.json') -var eachAsync = require('each-async') +var debug = require('debug')(pkg.name) var workerFarm = require('worker-farm') +var series = require('run-series') var minimistOptions = require('./minimist-options') require('update-notifier')({pkg: pkg}).notify() @@ -22,6 +23,8 @@ if (!filename) cli.showHelp() var flags = cli.flags +debug(flags) + var fileArgs = process.argv.slice(process.argv.indexOf(filename) + 1) var workers = flags.workers * flags.cores @@ -83,20 +86,24 @@ var farmOptions = { // the first request comes through. autoStart: true } - var workersRange = range(workers) var spawnWorker = workerFarm(farmOptions, path.resolve(filename)) -function spawnDelay (workerArgs, cb) { - spawnWorker(workerArgs, process.exit) - setTimeout(cb, flags.delay) +function spawnWorkerDelay (workerArgs) { + return function (cb) { + debug('spawning %s', workerArgs) + spawnWorker(workerArgs, process.exit) + setTimeout(cb, flags.delay) + } } function closeFarm () { workerFarm.end(spawnWorker) } -eachAsync(workersRange, function (worker, index, next) { +var spawnWorkers = workersRange.map(function (worker) { var workerArgs = fileArgs.concat(['--worker=' + worker]) - return spawnDelay(workerArgs, next) -}, closeFarm) + return spawnWorkerDelay(workerArgs) +}) + +series(spawnWorkers, closeFarm) diff --git a/package.json b/package.json index 8e486ba..d71941a 100644 --- a/package.json +++ b/package.json @@ -27,12 +27,13 @@ "worker" ], "dependencies": { - "each-async": "~1.1.1", "exists-file": "~1.0.0", "lodash.range": "~3.1.2", "meow": "~3.7.0", "update-notifier": "~0.6.0", - "worker-farm": "~1.3.1" + "worker-farm": "~1.3.1", + "debug": "~2.2.0", + "run-series": "~1.1.4" }, "devDependencies": { "git-dirty": "latest",