Skip to content

Instantly share code, notes, and snippets.

@Nautigsam
Created March 17, 2016 18:31
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 Nautigsam/cf246d0953bd3f2ee553 to your computer and use it in GitHub Desktop.
Save Nautigsam/cf246d0953bd3f2ee553 to your computer and use it in GitHub Desktop.
ES2015 chronometer
'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