Skip to content

Instantly share code, notes, and snippets.

@emgeee
Created November 2, 2015 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emgeee/cf74d46057c09cf8d404 to your computer and use it in GitHub Desktop.
Save emgeee/cf74d46057c09cf8d404 to your computer and use it in GitHub Desktop.
var N = 50
function asyncFunc (cb) {
setTimeout(() => cb(Math.random()), 100)
}
function loop (N, results, done) {
// Recursion base-case
if (results.length >= N) return done(results)
asyncFunc((res) => {
results.push(res)
loop(max, results, done)
})
}
let randomNumbers = []
loop(N, randomNumbers, function (results) {
console.log(results)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment