diff --git a/bin/cli/index.js b/bin/cli/index.js index 0467e2e..4218adf 100755 --- a/bin/cli/index.js +++ b/bin/cli/index.js @@ -3,7 +3,7 @@ 'use strict' const pkg = require('../../package.json') -require('update-notifier')({pkg}).notify() +require('update-notifier')({ pkg }).notify() const debug = require('debug')(pkg.name) const workerFarm = require('worker-farm') @@ -23,10 +23,10 @@ const cli = getFarmArgs(argv.farm) const [filename] = cli.input if (!filename) cli.showHelp() -const {file: fileOpts} = argv -const {flags: farmOpts} = cli +const { file: fileOpts } = argv +const { flags: farmOpts } = cli -const {delayBetweenWorkers} = farmOpts +const { delayBetweenWorkers } = farmOpts const numWorkers = getNumWorkers(farmOpts) const workersRange = [...Array(numWorkers).keys()] const spawnWorkers = workersRange.map(spawnWorker) diff --git a/bin/get-farm-args/index.js b/bin/get-farm-args/index.js index 036fd4c..2f23031 100644 --- a/bin/get-farm-args/index.js +++ b/bin/get-farm-args/index.js @@ -29,7 +29,7 @@ function getFarmArgs (argv) { const config = loadConfig(file) const flags = Object.assign({}, defaults, config, cli.flags) - return Object.assign(cli, {flags}) + return Object.assign(cli, { flags }) } module.exports = getFarmArgs diff --git a/examples/basic/index.js b/examples/basic/index.js index fe4a836..6ae6082 100644 --- a/examples/basic/index.js +++ b/examples/basic/index.js @@ -3,7 +3,7 @@ const shared = [] module.exports = function (opts) { - const {worker} = opts + const { worker } = opts console.log('-----------------------------') console.log(`Hello I'm worker #${worker}`) const printSharedWorkers = shared.join(' ') || 'none' diff --git a/examples/factorial/index.js b/examples/factorial/index.js index 3e1ca9f..404b995 100644 --- a/examples/factorial/index.js +++ b/examples/factorial/index.js @@ -1,6 +1,6 @@ 'use strict' -const {ensureAsync, waterfall, whilst} = require('async') +const { ensureAsync, waterfall, whilst } = require('async') const mutexify = require('mutexify') const memo = [1, 1] @@ -17,18 +17,24 @@ const lock = mutexify() let index = 0 module.exports = function (opts, cb) { - const {worker: workerNum, n} = opts + const { worker: workerNum, n } = opts whilst( () => index < n, - done => waterfall([ - next => lock(release => release(next(null, ++index))), - ensureAsync((num, next) => { - const value = factorial(num) - console.log(`#${workerNum} factorial value=${index} result=${value}`) - return next() - }) - ], done), + done => + waterfall( + [ + next => lock(release => release(next(null, ++index))), + ensureAsync((num, next) => { + const value = factorial(num) + console.log( + `#${workerNum} factorial value=${index} result=${value}` + ) + return next() + }) + ], + done + ), cb ) } diff --git a/examples/fibonacci-redis/index.js b/examples/fibonacci-redis/index.js index e025894..7aa7158 100644 --- a/examples/fibonacci-redis/index.js +++ b/examples/fibonacci-redis/index.js @@ -1,6 +1,6 @@ 'use strict' -const {ensureAsync, waterfall, during} = require('async') +const { ensureAsync, waterfall, during } = require('async') const redis = require('redis').createClient() const pify = require('pify') const memo = [0, 1] @@ -13,24 +13,29 @@ const fibonacciMemo = function (n) { return result } -const fibonacci = num => num <= 1 ? 1 : fibonacci(num - 1) + fibonacci(num - 2) +const fibonacci = num => + num <= 1 ? 1 : fibonacci(num - 1) + fibonacci(num - 2) const REDIS_KEY = 'fibonacci' module.exports = async function (opts, cb) { - const {worker: workerNum, memo, n, isMaster} = opts + const { worker: workerNum, memo, n, isMaster } = opts const fn = memo ? fibonacciMemo : fibonacci if (isMaster) await pify(redis.set(REDIS_KEY, 0)) during( next => redis.get(REDIS_KEY, (err, num) => next(err, num < n)), - done => waterfall([ - next => redis.incr(REDIS_KEY, (err, n) => next(err, n)), - ensureAsync((n, next) => { - const result = fn(n) - console.log(`#${workerNum} fibonacci n=${n} result=${result}`) - return next() - }) - ], done), + done => + waterfall( + [ + next => redis.incr(REDIS_KEY, (err, n) => next(err, n)), + ensureAsync((n, next) => { + const result = fn(n) + console.log(`#${workerNum} fibonacci n=${n} result=${result}`) + return next() + }) + ], + done + ), cb ) } diff --git a/examples/fibonacci/index.js b/examples/fibonacci/index.js index fa15581..2da9d8c 100644 --- a/examples/fibonacci/index.js +++ b/examples/fibonacci/index.js @@ -1,6 +1,6 @@ 'use strict' -const {ensureAsync, waterfall, whilst} = require('async') +const { ensureAsync, waterfall, whilst } = require('async') const mutexify = require('mutexify') const memo = [0, 1] @@ -13,25 +13,32 @@ const fibonacciMemo = function (n) { return result } -const fibonacci = num => num <= 1 ? 1 : fibonacci(num - 1) + fibonacci(num - 2) +const fibonacci = num => + num <= 1 ? 1 : fibonacci(num - 1) + fibonacci(num - 2) const lock = mutexify() let index = 0 module.exports = function (opts, cb) { - const {worker: workerNum, memo, n} = opts + const { worker: workerNum, memo, n } = opts const fn = memo ? fibonacciMemo : fibonacci whilst( () => index < n, - done => waterfall([ - next => lock(release => release(next(null, ++index))), - ensureAsync((num, next) => { - const value = fn(num) - console.log(`#${workerNum} fibonacci value=${index} result=${value}`) - return next() - }) - ], done), + done => + waterfall( + [ + next => lock(release => release(next(null, ++index))), + ensureAsync((num, next) => { + const value = fn(num) + console.log( + `#${workerNum} fibonacci value=${index} result=${value}` + ) + return next() + }) + ], + done + ), cb ) } diff --git a/package.json b/package.json index af648f3..c415d27 100644 --- a/package.json +++ b/package.json @@ -27,12 +27,12 @@ "worker" ], "dependencies": { - "debug": "~3.1.0", + "debug": "~4.1.1", "exists-file": "~3.0.2", "is-directory": "~0.3.1", "is-file": "~1.0.0", "meow": "~5.0.0", - "run-series": "~1.1.4", + "run-series": "~1.1.8", "update-notifier": "~2.5.0", "worker-farm": "~1.6.0" }, diff --git a/test/parse-argv-spec.js b/test/parse-argv-spec.js index 19b858d..e42ad78 100644 --- a/test/parse-argv-spec.js +++ b/test/parse-argv-spec.js @@ -6,13 +6,13 @@ const parseArgv = require('../bin/parse-args') describe('parse args', function () { it('farm opts', function () { const argv = ['-w', '1', 'examples/basic', '--test'] - const {farm: farmConfig} = parseArgv(argv) + const { farm: farmConfig } = parseArgv(argv) should(farmConfig).be.eql(['-w', '1', 'examples/basic']) }) it('file opts', function () { const argv = ['-w', '1', 'examples/basic', '--test'] - const {file: fileConfig} = parseArgv(argv) + const { file: fileConfig } = parseArgv(argv) should(fileConfig).be.eql(['--test']) }) })