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

Commit

Permalink
build: fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Feb 3, 2019
1 parent 4949d5b commit 57ed1e5
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 42 deletions.
8 changes: 4 additions & 4 deletions bin/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bin/get-farm-args/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion examples/basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
26 changes: 16 additions & 10 deletions examples/factorial/index.js
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
)
}
27 changes: 16 additions & 11 deletions examples/fibonacci-redis/index.js
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
)
}
29 changes: 18 additions & 11 deletions examples/fibonacci/index.js
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
)
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 2 additions & 2 deletions test/parse-argv-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
})
})

0 comments on commit 57ed1e5

Please sign in to comment.