Created
November 23, 2016 02:49
-
-
Save o0/9471dc503bda230757ec3963074a95eb to your computer and use it in GitHub Desktop.
Version of Either monad(https://gist.github.com/o0/d517fbedd73ee759cb3beaf7574bd048) without external requirements on ES2015 Promises
This file contains hidden or 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'; | |
const tick = level => level.time === 1 ? | |
Promise.reject(`Time's up`) : | |
Promise.resolve(Object.assign({}, level, { time: level.time - 1 })); | |
const countdown = (level) => { | |
console.info(level.time); | |
setTimeout(() => tick(level).then(countdown, console.error), 1000); | |
}; | |
countdown({ time: 5 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment