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
});









share|improve this question






















  • 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










  • 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

















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
});









share|improve this question






















  • 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










  • 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















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
});









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 15:04









Dalie

236111




236111












  • 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










  • 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










  • 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


















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



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma