Compare commits

...

2 Commits

Author SHA1 Message Date
Christian Weimann
47d6b80511 refactor(TimerMgr): streamline timer identification and logging 2025-01-10 06:08:04 +01:00
Christian Weimann
33e5781ee8 fix(TimerMgr): add warning for rescheduling non-existent timers 2025-01-10 06:05:20 +01:00

View File

@@ -18,23 +18,23 @@ class TimerMgr {
this.#timers[id] = actions.ScriptExecution.createTimer(id, timeout, func);
}
cancel(identifier) {
// Return if no timer with the respactive identifier is available
if (!this.#timers.hasOwnProperty(identifier)) {
log.debug(`No timer with identifier ${identifier} available to cancel`);
cancel(id) {
// Return if no timer with the respactive id is available
if (!this.hasTimer(id)) {
log.warn(`No timer with id ${id} available to cancel`);
return false;
}
// Check if timer is active
if (!this.#timers[identifier].isActive()) {
log.debug(`Timer with identifier ${identifier} not running. Cancel anyway`);
if (!this.#timers[id].isActive()) {
log.debug(`Timer with id ${id} not running. Cancel anyway`);
} else {
log.debug(`Cancel timer with identifier ${identifier}`);
log.debug(`Cancel timer with identifier ${id}`);
}
// Cancel timer
this.#timers[identifier].cancel();
delete this.#timers[identifier];
this.#timers[id].cancel();
delete this.#timers[id];
}
hasTimer(id) {
@@ -66,6 +66,10 @@ class TimerMgr {
}
reschedule(id, timeout) {
if (!this.hasTimer(id)) {
log.warn(`Cannot reschedule non-existent timer with id ${id}`);
return false;
}
this.#timers[id].reschedule(timeout);
}
}