From 43b9b89d7e27562716b6a670c114ac8f4857d614 Mon Sep 17 00:00:00 2001 From: Badr Bouslikhin Date: Fri, 26 Feb 2021 21:50:32 +0100 Subject: [PATCH] fix: add debounce to avoid parallel executions --- main.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.ts b/main.ts index a8188dc..7e998ce 100644 --- a/main.ts +++ b/main.ts @@ -4,6 +4,7 @@ import { Plugin, PluginSettingTab, Setting, + debounce, TFile, } from "obsidian"; import type moment from "moment"; @@ -38,7 +39,11 @@ export default class Changelog extends Plugin { hotkeys: [], }); - this.watchVaultChange = this.watchVaultChange.bind(this); + this.watchVaultChange = debounce( + this.watchVaultChange.bind(this), + 200, + false + ); this.registerWatchVaultEvents(); } @@ -54,11 +59,11 @@ export default class Changelog extends Plugin { } } - async watchVaultChange(file: any) { + watchVaultChange(file: any) { if (file.path === this.settings.changelogFilePath) { return; } else { - await this.writeChangelog(); + this.writeChangelog(); } }