I’ve a operate inside scheduler that calls the operate after each 19 seconds and the capabilities sends knowledge to the backend.
each time i swap the display screen or decrease the browser sport tab, The scheduler pauses which i need to keep away from because the delay for which the scheduler does’nt sends the info will get very massive as browser window is minimized or tab is switched and scheduler is paused.
Is there any approach i can keep away from scheduler from getting paused ?
Or Can setInterval present the specified end result ?
Thanks upfront.
1 Like
I’ve the identical downside.
I attempt to use replace() to repair this subject.
For a depend down timer, thie subject will be resolved.
Nonetheless, when utilized to a tween, the identical downside nonetheless happens.
Does anybody have a greater resolution?
import { _decorator, Element, director, Node } from 'cc';
const { ccclass, property } = _decorator;
sort CountdownTask = {
targetTime: quantity;
persecondCallback: (remainingSeconds: quantity) => void;
endTimerCallback: () => void;
lastSecond: quantity;
};
@ccclass('ScheduleExtra')
export class ScheduleExtra extends Element {
personal static Occasion: ScheduleExtra;
protected onLoad() {
if (ScheduleExtra.Occasion == null) {
ScheduleExtra.Occasion = this;
director.addPersistRootNode(this.node);
} else if (ScheduleExtra.Occasion != this) {
this.node.destroy();
}
}
personal static duties: CountdownTask[] = [];
replace() {
const now = Date.now();
for (let i = ScheduleExtra.duties.size - 1; i >= 0; i--) {
const process = ScheduleExtra.duties[i];
const remaining = Math.max(0, (process.targetTime - now) / 1000);
const floored = Math.flooring(remaining);
if (floored !== process.lastSecond) {
process.lastSecond = floored;
process.persecondCallback?.(remaining); // 傳原始浮點秒數
}
if (remaining void, endTimerCallback: () => void) {
const newTask: CountdownTask = {
targetTime: Date.now() + seconds * 1000,
persecondCallback,
endTimerCallback,
lastSecond: -1
};
this.duties.push(newTask);
}
}
// The right way to use
//personal runTimer0() {
// ScheduleExtra.StartCountdown(
// this.timer0,
// (remaining) => {
// console.log(`Timer0 Remaining:${remaining} second`);
// this.Lbl_Timer0.string = remaining.toString();
// },
// () => {
// console.log("Rely down over!");
// }
// );
// }
sort or paste code right here