From 34a79857405b0dd67b7e830bb54a9e01aec3a5d4 Mon Sep 17 00:00:00 2001 From: David Martos Date: Mon, 20 May 2024 16:31:06 +0200 Subject: [PATCH] make acquireIfFree sync --- clients/typescript/src/satellite/process.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clients/typescript/src/satellite/process.ts b/clients/typescript/src/satellite/process.ts index 9a11fc9147..75b29ce608 100644 --- a/clients/typescript/src/satellite/process.ts +++ b/clients/typescript/src/satellite/process.ts @@ -220,12 +220,12 @@ export class SatelliteProcess implements Satellite { let release: MutexInterface.Releaser if (skipIfRunning) { - const maybeRelease = await this.acquireIfFree(this.snapshotMutex) + const maybeRelease = this.acquireIfFree(this.snapshotMutex) if (!maybeRelease) { // Skip the snapshot return } - release = maybeRelease + release = await maybeRelease } else { release = await this.snapshotMutex.acquire() } @@ -239,17 +239,17 @@ export class SatelliteProcess implements Satellite { /** * Only acquire the mutex if it's not already locked. + * WARNING: For clearer intentions of this code, we keep the function "sync" + * @returns The releaser if the mutex was free, null otherwise. */ - private async acquireIfFree( - mutex: Mutex - ): Promise { + private acquireIfFree(mutex: Mutex): Promise | null { // WARNING: We can do this check right before the mutex acquire because there is no async // call until then, so the event loop won't interleave other code. // More context here: https://github.com/electric-sql/electric/pull/1273 if (mutex.isLocked()) { return null } - return await mutex.acquire() + return mutex.acquire() } async start(authConfig?: AuthConfig): Promise {