Skip to content

Instantly share code, notes, and snippets.

@danieldram
Created November 18, 2016 20:19
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 danieldram/d4a8de05eae329fe24592740318cfc5a to your computer and use it in GitHub Desktop.
Save danieldram/d4a8de05eae329fe24592740318cfc5a to your computer and use it in GitHub Desktop.
Recursive Random Time Function Cxecution with JavaScript ES6 Generators
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