Compare commits
2 Commits
e299b96d15
...
47d6b80511
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47d6b80511 | ||
|
|
33e5781ee8 |
@@ -18,23 +18,23 @@ class TimerMgr {
|
|||||||
this.#timers[id] = actions.ScriptExecution.createTimer(id, timeout, func);
|
this.#timers[id] = actions.ScriptExecution.createTimer(id, timeout, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel(identifier) {
|
cancel(id) {
|
||||||
// Return if no timer with the respactive identifier is available
|
// Return if no timer with the respactive id is available
|
||||||
if (!this.#timers.hasOwnProperty(identifier)) {
|
if (!this.hasTimer(id)) {
|
||||||
log.debug(`No timer with identifier ${identifier} available to cancel`);
|
log.warn(`No timer with id ${id} available to cancel`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if timer is active
|
// Check if timer is active
|
||||||
if (!this.#timers[identifier].isActive()) {
|
if (!this.#timers[id].isActive()) {
|
||||||
log.debug(`Timer with identifier ${identifier} not running. Cancel anyway`);
|
log.debug(`Timer with id ${id} not running. Cancel anyway`);
|
||||||
} else {
|
} else {
|
||||||
log.debug(`Cancel timer with identifier ${identifier}`);
|
log.debug(`Cancel timer with identifier ${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel timer
|
// Cancel timer
|
||||||
this.#timers[identifier].cancel();
|
this.#timers[id].cancel();
|
||||||
delete this.#timers[identifier];
|
delete this.#timers[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
hasTimer(id) {
|
hasTimer(id) {
|
||||||
@@ -66,6 +66,10 @@ class TimerMgr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reschedule(id, timeout) {
|
reschedule(id, timeout) {
|
||||||
|
if (!this.hasTimer(id)) {
|
||||||
|
log.warn(`Cannot reschedule non-existent timer with id ${id}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
this.#timers[id].reschedule(timeout);
|
this.#timers[id].reschedule(timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user