Skip to content

Instantly share code, notes, and snippets.

@o0
Created November 23, 2016 02:49
Show Gist options
  • Save o0/9471dc503bda230757ec3963074a95eb to your computer and use it in GitHub Desktop.
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
'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