Created
November 18, 2016 20:19
-
-
Save danieldram/d4a8de05eae329fe24592740318cfc5a to your computer and use it in GitHub Desktop.
Recursive Random Time Function Cxecution with JavaScript ES6 Generators
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
function* gen(){ | |
var rand = _.random(1000,5000); | |
return ()=>{ | |
return setTimeout(()=>{ | |
console.log('hi'); | |
console.log(rand); | |
return gen().next().value(); | |
}, rand) | |
} | |
} | |
var x = gen(); | |
var y = x.next(); | |
console.log(y.value()); | |
//outputs | |
//"hi" every random time interval between 1s and 5s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment