Created
March 17, 2016 18:31
-
-
Save Nautigsam/cf246d0953bd3f2ee553 to your computer and use it in GitHub Desktop.
ES2015 chronometer
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
'use strict' | |
let it=(function*(){ | |
let i=1 | |
while(1){ | |
yield new Promise((resolve)=>{ | |
setTimeout(()=>{ | |
resolve(i++) | |
},1000) | |
}) | |
} | |
}()); | |
(function c(f){ | |
let r=it.next(),v=r.value | |
if(r.done){ | |
return v | |
}else{ | |
return v | |
.then(f) | |
.then(()=>c(f)) | |
} | |
}((n)=>console.log(`${n} seconds passed`))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment