Skip to content

Commit 851c2c1

Browse files
committed
timer: use timeout option for ETimer.IDLE instead of delay
Signed-off-by: 🕷️ <[email protected]>
1 parent 60eaa2f commit 851c2c1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/api/time.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type TTimerAnimation = TTimerMeasurable & {
108108
};
109109
type TTimerIdle = TTimerMeasurable & {
110110
type: ETimer.IDLE;
111-
delay: number;
111+
timeout: number;
112112
};
113113
type TTimerTask = TTimerMeasurable & {
114114
type: ETimer.TASK;
@@ -160,6 +160,7 @@ const timerApi = __mirror__
160160
*/
161161
export class Timer {
162162
delay: number = 0;
163+
timeout: number = 0;
163164
/** callback's self-time in milliseconds */
164165
callbackSelfTime: number = -1;
165166
#handler: number = 0;
@@ -174,10 +175,11 @@ export class Timer {
174175

175176
if (
176177
this.#options.type === ETimer.TIMEOUT ||
177-
this.#options.type === ETimer.IDLE ||
178178
this.#options.type === ETimer.TASK
179179
) {
180180
this.delay = this.#options.delay;
181+
} else if (this.#options.type === ETimer.IDLE) {
182+
this.timeout = this.#options.timeout;
181183
}
182184

183185
if (this.#options.measurable) {
@@ -208,7 +210,7 @@ export class Timer {
208210
this.#handler = timerApi.requestIdleCallback((...argsIC) => {
209211
this.#handler = 0;
210212
this.trigger(...[...args, ...argsIC]);
211-
}, { timeout: this.delay });
213+
}, { timeout: this.timeout });
212214
} else if (this.#options.type === ETimer.TASK) {
213215
this.#abortController = new AbortController();
214216
timerApi.postTask(() => {

tests/time_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('Timer - idle', () => {
145145
const timerArgExpected = 100;
146146
let hasIdleArgs = false;
147147
const task = new Timer(
148-
{ type: ETimer.IDLE, delay: DELAY },
148+
{ type: ETimer.IDLE, timeout: DELAY },
149149
(_timerArg: number, deadline: IdleDeadline) => {
150150
counter++;
151151
timerArg = _timerArg;

0 commit comments

Comments
 (0)