Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created August 27, 2014 23:23
Show Gist options
  • Save ajcrites/8320945845e856db3eb5 to your computer and use it in GitHub Desktop.
Save ajcrites/8320945845e856db3eb5 to your computer and use it in GitHub Desktop.
// Functional serialized asynchronous recursion
(function serialRandomTimeout(x) {
if (x.value) {
setTimeout(function () {
console.log(x.value);
serialRandomTimeout(x.next)
}, Math.random() * 1000);
}
})([1,2,3].reduceRight(function (prev, next) {
prev.next = JSON.parse(JSON.stringify(prev));
prev.value = next;
return prev;
}, {}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment