a zip code crypto-currency system good for red ONLY

timer.js 873B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. (function() {
  2. var Timer;
  3. exports.Timer = Timer = (function() {
  4. function Timer(func) {
  5. this.func = func;
  6. this.running = false;
  7. this.id = null;
  8. this._handler = (function(_this) {
  9. return function() {
  10. _this.running = false;
  11. _this.id = null;
  12. return _this.func();
  13. };
  14. })(this);
  15. }
  16. Timer.prototype.start = function(timeout) {
  17. if (this.running) {
  18. clearTimeout(this.id);
  19. }
  20. this.id = setTimeout(this._handler, timeout);
  21. return this.running = true;
  22. };
  23. Timer.prototype.stop = function() {
  24. if (this.running) {
  25. clearTimeout(this.id);
  26. this.running = false;
  27. return this.id = null;
  28. }
  29. };
  30. return Timer;
  31. })();
  32. Timer.start = function(timeout, func) {
  33. return setTimeout(func, timeout);
  34. };
  35. }).call(this);