This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
const {whilst} = require('async') | ||
const minDelay = require('min-delay')(500) | ||
|
||
function fibonacci (num) { | ||
if (num <= 1) return 1 | ||
return fibonacci(num - 1) + fibonacci(num - 2) | ||
} | ||
|
||
module.exports = function (opts, done) { | ||
const {worker} = opts | ||
const condition = () => true | ||
|
||
function log () { | ||
const args = [`#${worker}`].concat(...arguments) | ||
console.log(...args) | ||
} | ||
|
||
whilst( | ||
condition, | ||
function (next) { | ||
const fn = () => { | ||
const result = fibonacci(worker) | ||
log(`fibonacci result is ${result}`) | ||
next() | ||
} | ||
minDelay(fn) | ||
}, | ||
process.exit | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters