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

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Mar 7, 2017
1 parent 0ed8d0f commit 5487bac
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bin/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ if (!filename) cli.showHelp()

const {file: fileOpts} = argv
const {flags: farmOpts} = cli

const {delayBetweenWorkers} = farmOpts
const numWorkers = getNumWorkers(farmOpts)
const workersRange = [...Array(numWorkers).keys()]
const spawnWorkers = workersRange.map(spawnWorker)

const spawnWorkers = workersRange.map(function (worker) {
const workerArgs = getWorkerArgs(fileOpts, worker)
function spawnWorker (id) {
const workerArgs = getWorkerArgs(fileOpts, id)
return spawnWorkerDelay(workerArgs, delayBetweenWorkers)
})
}

function spawnWorkerDelay (args, delay) {
function spawnWorker (cb) {
const parsedArgs = minimist(args)
debug('spawning %o', parsedArgs)
farm(parsedArgs, process.exit)
setTimeout(cb, delay)
return process.nextTick(cb, delay)
}

return spawnWorker
Expand Down

0 comments on commit 5487bac

Please # to comment.