SeverinDK / moment-timer

Timer plugin for Moment.js that allows creation of setInterval and setTimeout-like timers.
MIT License
110 stars 33 forks source link

Can't stop timer #2

Closed frutality closed 8 years ago

frutality commented 8 years ago

Hi!

Trying to stop timer once it runs out.

var realTimer;
  realTimer = moment.duration(5, 'seconds').timer({
    loop: false,
    start: true
  }, function () {
    console.log('timer cb');
    realTimer.stop();
    console.log(realTimer.isStopped()); // false
  });

Even tried to stop it like this:

setTimeout(function () {
    realTimer.stop();
    console.log(realTimer.isStopped()); // false
  }, 10000);
SeverinDK commented 8 years ago

I will look into it as soon as possible. Apparently there is a problem with the way the non-loop timer works. After its duration reaches zero, it sets a variable that prevents it from calling .stop()

SeverinDK commented 8 years ago

Sorry that I haven't been able to get around to this problem yet. I will look at it tomorrow or the day after that. I have been busy with some new job stuff, that had first priority. But I will get to it asap :)

frutality commented 8 years ago

Ah, don't worry. I decided to use standard js setTimeout for my goals. Probably in more complicated cases moment-timer would be very helpful, but my case is simple :)

SeverinDK commented 8 years ago

No problem. I will still come up with a fix for it, just in case someone else runs into the same problem.

yigitaybuga commented 7 years ago

Any news on this? It is almost a year.