diff --git a/src/plugins/Reminders.ts b/src/plugins/Reminders.ts index e4f40d67..4449144f 100644 --- a/src/plugins/Reminders.ts +++ b/src/plugins/Reminders.ts @@ -27,6 +27,7 @@ export class RemindersPlugin extends ZeppelinPlugin { protected tries: Map; private postRemindersTimeout; + private unloaded = false; getDefaultOptions(): IPluginOptions { return { @@ -51,6 +52,11 @@ export class RemindersPlugin extends ZeppelinPlugin { this.postDueRemindersLoop(); } + onUnload() { + clearTimeout(this.postRemindersTimeout); + this.unloaded = true; + } + async postDueRemindersLoop() { const pendingReminders = await this.reminders.getDueReminders(); for (const reminder of pendingReminders) { @@ -74,7 +80,9 @@ export class RemindersPlugin extends ZeppelinPlugin { await this.reminders.delete(reminder.id); } - this.postRemindersTimeout = setTimeout(() => this.postDueRemindersLoop(), REMINDER_LOOP_TIME); + if (!this.unloaded) { + this.postRemindersTimeout = setTimeout(() => this.postDueRemindersLoop(), REMINDER_LOOP_TIME); + } } @d.command("remind", " [reminder:string$]", {