Using RxJS's `generate` to create a non-drifiting timer, how to use the `scheduler`?
up vote
0
down vote
favorite
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
);
timer rxjs scheduler rxjs6
add a comment |
up vote
0
down vote
favorite
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
);
timer rxjs scheduler rxjs6
Why don't use just useintervalwhich is implemented internally with a singlesetIntervalcall? Are you sayingsetIntervaldrifts?
– cartant
Nov 11 at 0:24
If I understand things correctly, yessetIntevalcan drift see: stackoverflow.com/a/985692/1378051
– Dalie
Nov 11 at 9: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 at 9:16
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
);
timer rxjs scheduler rxjs6
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
);
timer rxjs scheduler rxjs6
timer rxjs scheduler rxjs6
asked Nov 10 at 15:04
Dalie
241111
241111
Why don't use just useintervalwhich is implemented internally with a singlesetIntervalcall? Are you sayingsetIntervaldrifts?
– cartant
Nov 11 at 0:24
If I understand things correctly, yessetIntevalcan drift see: stackoverflow.com/a/985692/1378051
– Dalie
Nov 11 at 9: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 at 9:16
add a comment |
Why don't use just useintervalwhich is implemented internally with a singlesetIntervalcall? Are you sayingsetIntervaldrifts?
– cartant
Nov 11 at 0:24
If I understand things correctly, yessetIntevalcan drift see: stackoverflow.com/a/985692/1378051
– Dalie
Nov 11 at 9: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 at 9:16
Why don't use just use
interval which is implemented internally with a single setInterval call? Are you saying setInterval drifts?– cartant
Nov 11 at 0:24
Why don't use just use
interval which is implemented internally with a single setInterval call? Are you saying setInterval drifts?– cartant
Nov 11 at 0:24
If I understand things correctly, yes
setInteval can drift see: stackoverflow.com/a/985692/1378051– Dalie
Nov 11 at 9:11
If I understand things correctly, yes
setInteval can drift see: stackoverflow.com/a/985692/1378051– Dalie
Nov 11 at 9: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 at 9:16
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 at 9:16
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240230%2fusing-rxjss-generate-to-create-a-non-drifiting-timer-how-to-use-the-schedul%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why don't use just use
intervalwhich is implemented internally with a singlesetIntervalcall? Are you sayingsetIntervaldrifts?– cartant
Nov 11 at 0:24
If I understand things correctly, yes
setIntevalcan drift see: stackoverflow.com/a/985692/1378051– Dalie
Nov 11 at 9: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 at 9:16