From cfdad5f6088de4b8659a6f8ade596f1867af818f Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Thu, 2 Jan 2025 09:16:32 +0000 Subject: [PATCH] Rename locks --- .../src/sync-operations/{locks.ts => document-lock.ts} | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) rename plugin/src/sync-operations/{locks.ts => document-lock.ts} (77%) diff --git a/plugin/src/sync-operations/locks.ts b/plugin/src/sync-operations/document-lock.ts similarity index 77% rename from plugin/src/sync-operations/locks.ts rename to plugin/src/sync-operations/document-lock.ts index 8a28249e..a8a3b356 100644 --- a/plugin/src/sync-operations/locks.ts +++ b/plugin/src/sync-operations/document-lock.ts @@ -1,7 +1,7 @@ import type { RelativePath } from "src/database/document-metadata"; -const locked = new Set(), - waiters = new Map void)[]>(); +const locked = new Set(); +const waiters = new Map void)[]>(); export function tryLockDocument(relativePath: RelativePath): boolean { if (locked.has(relativePath)) { @@ -32,10 +32,14 @@ export async function waitForDocumentLock( export function unlockDocument(relativePath: RelativePath): void { if (!locked.has(relativePath)) { - throw new Error(`Document ${relativePath} is not locked`); + throw new Error( + `Document ${relativePath} is not locked, cannot unlock` + ); } + // Remove the first element to ensure FIFO unblocking order const nextWaiting = waiters.get(relativePath)?.shift(); + if (nextWaiting) { nextWaiting(); } else {