1
0

Improve comments

This commit is contained in:
2023-08-26 08:11:13 +02:00
parent 8bf1a60749
commit 98358d5c09

View File

@@ -15,30 +15,35 @@ class Timer {
} }
cancel(identifier) { cancel(identifier) {
// Return if no timer with the respactive identifier is available
if (!this.#timers.hasOwnProperty(identifier)) { if (!this.#timers.hasOwnProperty(identifier)) {
console.debug(`No timer with identifier ${identifier} available to cancel`); console.debug(`No timer with identifier ${identifier} available to cancel`);
return false; return false;
} }
// Check if timer is active
if (!this.#timers[identifier].isActive()) { if (!this.#timers[identifier].isActive()) {
console.debug(`Timer with identifier ${identifier} not running. Cancel anyway`); console.debug(`Timer with identifier ${identifier} not running. Cancel anyway`);
} else { } else {
console.debug(`Cancel timer with identifier ${identifier}`); console.debug(`Cancel timer with identifier ${identifier}`);
} }
// Cancel timer
this.#timers[identifier].cancel(); this.#timers[identifier].cancel();
delete this.#timers[identifier]; delete this.#timers[identifier];
} }
cancelAll() { cancelAll() {
// Fetch timers
let timers = Object.keys(this.#timers); let timers = Object.keys(this.#timers);
// Return if no timers available
if (timers.length == 0) { if (timers.length == 0) {
console.debug('No timers available to cancel'); console.debug('No timers available to cancel');
return false; return false;
} }
// Cancel all timers
for (let timer of timers) { for (let timer of timers) {
this.cancel(timer); this.cancel(timer);
} }