Skip to content

Commit 7f517cb

Browse files
committed
fix: intermittent watcher errors
re #42
1 parent 62253a3 commit 7f517cb

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Desktop/ScriptFolderWatcher.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,21 @@ class ScriptFolderWatcherImpl extends ScriptFolderWatcher {
2929
const invocableScriptsFolderFullPath = join(this.plugin?.app.vault.adapter.basePath ?? '', invocableScriptsFolder);
3030
this.watcher = watch(invocableScriptsFolderFullPath, { recursive: true }, (eventType: WatchEventType): void => {
3131
if (eventType === 'rename') {
32-
invokeAsyncSafely(() => onChange());
32+
invokeAsyncSafely(async () => {
33+
const RETRY_COUNT = 5;
34+
const RETRY_DELAY_IN_MILLISECONDS = 100;
35+
let lastError: unknown = null;
36+
for (let i = 0; i < RETRY_COUNT; i++) {
37+
try {
38+
await onChange();
39+
return;
40+
} catch (error) {
41+
await sleep(RETRY_DELAY_IN_MILLISECONDS);
42+
lastError = error;
43+
}
44+
}
45+
throw lastError;
46+
});
3347
}
3448
});
3549

0 commit comments

Comments
 (0)