0

In search for a timer - triggered every minute, on the minute - that doesn't drift, I found this solution. However I'm having difficulties understanding how to use / construct the last parameter scheduler?: SchedulerLike.

const noDrift = generate(
  0,
  _ => true, // start condition
  i => ++i,  // iterate
  i => i,    // result selector
  i =>  ...  // scheduler?: SchedulerLike; every minute on the minute, but how?
);

noDrift.subscribe(() => {
  // action
});

original solution that drifts:

const date = new Date();

// calculate how many ms are left till the full minute is reached
const tillNextFullMinute = (60 - date.getSeconds()) * 1000 - date.getMilliseconds();

// start on the next full minute, then just every minute
this.currentTime = timer(tillNextFullMinute, 60 * 1000);
this.currentTime.subscribe(value => {
  // action
});
Dalie
  • 626
  • 1
  • 7
  • 19
  • Why don't use just use `interval` which is implemented internally with a single `setInterval` call? Are you saying `setInterval` drifts? – cartant Nov 11 '18 at 00:24
  • 1
    If I understand things correctly, yes `setInteval` can drift see: https://stackoverflow.com/a/985692/1378051 – Dalie Nov 11 '18 at 09:11
  • That question is nine years old. You might want to check the behaviour of current implementations - which might or might not be better behaved. – cartant Nov 11 '18 at 09:16

0 Answers0