Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setInterval() function triggerred 100+ times at the same time. #239

Open
zjh1943 opened this issue Feb 3, 2020 · 1 comment
Open

setInterval() function triggerred 100+ times at the same time. #239

zjh1943 opened this issue Feb 3, 2020 · 1 comment

Comments

@zjh1943
Copy link

zjh1943 commented Feb 3, 2020

Code Explain

Code like the below:

later.date.localTime();

const timeStr = moment().add(1, 'm').format('HH:mm'); // time of next minute
const text = `at ${timeStr} also every 1 hour`; // want to trigger `fn` at next minute and every hour from now on.

console.log(`text: ${text}`)
const sched = later.parse.text(text);

console.log(`next 10 occurence: `, later.schedule(sched).next(24)); // this display right.
const fn = function() {
  console.log(`curr time: `, moment().format('HH:mm:ss'));
  console.log(`next 10 occurence: `, later.schedule(sched).next(24));
};
later.setInterval(fn, sched); // the `fn` function will be triggered 100+ times after one minute from now on.

As commented above.

  1. I want to trigger at next minute AND every 1 hour from now on.
  2. later.schedule.next() function works well. It displays exactly what I expect.
  3. But, when invoke setInterval(), fn will be invoked 100+ times at the next minute in a flash.

How to Replay

You can replay the bug on https://jsfiddle.net/xLobgnuh/6/:

  1. open url.
  2. open console.
  3. run.
  4. wait the next minute come.

Log

When you run the code above, console log will be like this:

LOG - CLICK TO SHOW

(index):39 text: at 17:27 also every 1 hour
(index):42 next 10 occurence:  (24) [Mon Feb 03 2020 17:26:27 GMT+0800 (中国标准时间), Mon Feb 03 2020 17:27:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 18:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 19:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 20:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 21:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 22:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 23:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 00:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 01:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 02:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 03:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 04:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 05:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 06:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 07:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 08:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 09:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 10:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 11:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 12:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 13:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 14:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 15:00:00 GMT+0800 (中国标准时间)]0: Mon Feb 03 2020 17:26:27 GMT+0800 (中国标准时间) {}1: Mon Feb 03 2020 17:27:00 GMT+0800 (中国标准时间) {}2: Mon Feb 03 2020 18:00:00 GMT+0800 (中国标准时间) {}3: Mon Feb 03 2020 19:00:00 GMT+0800 (中国标准时间) {}4: Mon Feb 03 2020 20:00:00 GMT+0800 (中国标准时间) {}5: Mon Feb 03 2020 21:00:00 GMT+0800 (中国标准时间) {}6: Mon Feb 03 2020 22:00:00 GMT+0800 (中国标准时间) {}7: Mon Feb 03 2020 23:00:00 GMT+0800 (中国标准时间) {}8: Tue Feb 04 2020 00:00:00 GMT+0800 (中国标准时间) {}9: Tue Feb 04 2020 01:00:00 GMT+0800 (中国标准时间) {}10: Tue Feb 04 2020 02:00:00 GMT+0800 (中国标准时间) {}11: Tue Feb 04 2020 03:00:00 GMT+0800 (中国标准时间) {}12: Tue Feb 04 2020 04:00:00 GMT+0800 (中国标准时间) {}13: Tue Feb 04 2020 05:00:00 GMT+0800 (中国标准时间) {}14: Tue Feb 04 2020 06:00:00 GMT+0800 (中国标准时间) {}15: Tue Feb 04 2020 07:00:00 GMT+0800 (中国标准时间) {}16: Tue Feb 04 2020 08:00:00 GMT+0800 (中国标准时间) {}17: Tue Feb 04 2020 09:00:00 GMT+0800 (中国标准时间) {}18: Tue Feb 04 2020 10:00:00 GMT+0800 (中国标准时间) {}19: Tue Feb 04 2020 11:00:00 GMT+0800 (中国标准时间) {}20: Tue Feb 04 2020 12:00:00 GMT+0800 (中国标准时间) {}21: Tue Feb 04 2020 13:00:00 GMT+0800 (中国标准时间) {}22: Tue Feb 04 2020 14:00:00 GMT+0800 (中国标准时间) {}23: Tue Feb 04 2020 15:00:00 GMT+0800 (中国标准时间) {}length: 24__proto__: Array(0)
(index):44 curr time:  17:27:00
(index):45 next 10 occurence:  (24) [Mon Feb 03 2020 17:27:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 17:27:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 18:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 19:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 20:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 21:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 22:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 23:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 00:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 01:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 02:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 03:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 04:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 05:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 06:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 07:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 08:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 09:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 10:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 11:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 12:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 13:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 14:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 15:00:00 GMT+0800 (中国标准时间)]
(index):44 curr time:  17:27:00
(index):45 next 10 occurence:  (24) [Mon Feb 03 2020 17:27:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 17:27:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 18:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 19:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 20:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 21:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 22:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 23:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 00:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 01:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 02:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 03:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 04:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 05:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 06:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 07:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 08:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 09:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 10:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 11:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 12:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 13:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 14:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 15:00:00 GMT+0800 (中国标准时间)]
(index):44 curr time:  17:27:00
(index):45 next 10 occurence:  (24) [Mon Feb 03 2020 17:27:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 17:27:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 18:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 19:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 20:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 21:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 22:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 23:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 00:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 01:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 02:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 03:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 04:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 05:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 06:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 07:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 08:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 09:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 10:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 11:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 12:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 13:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 14:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 15:00:00 GMT+0800 (中国标准时间)]

... (200+ lines omit) ....

(index):44 curr time:  17:27:01
(index):45 next 10 occurence:  (24) [Mon Feb 03 2020 17:27:01 GMT+0800 (中国标准时间), Mon Feb 03 2020 18:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 19:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 20:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 21:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 22:00:00 GMT+0800 (中国标准时间), Mon Feb 03 2020 23:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 00:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 01:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 02:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 03:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 04:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 05:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 06:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 07:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 08:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 09:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 10:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 11:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 12:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 13:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 14:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 15:00:00 GMT+0800 (中国标准时间), Tue Feb 04 2020 16:00:00 GMT+0800 (中国标准时间)]

@hufftheweevil
Copy link

This issue and entire repo is a little cold, but in case anyone stumbles upon here with a similar issue, here's my two cents.

I had a similar issue, but I was using simple schedules, instead of any of the schedule-building methods. I eventually discovered it was an issue where I had a schedule that included [ {m:[30]}, {h:[0,9]} ]. I wanted it to fire at the bottom of every hour, and also at the top of hours 0 and 9 - and I thought that was how to do it. As @zjh1943 mentioned above, the later.schedule.next() seemed to indicate that everything would go according to my plan. However, the setInterval() went haywire at 0030 and 0930, calling over and over again. To fix, I changed it to [ {m:[30]}, {h:[0,9], m:[0]} ] so that the 2nd schedule was explicit with its' minutes. It's not clear from the documentation if this is how it is supposed to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants