Skip to content

Commit

Permalink
make acquireIfFree sync
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmartos96 committed May 20, 2024
1 parent b06b941 commit 34a7985
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions clients/typescript/src/satellite/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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<MutexInterface.Releaser | null> {
private acquireIfFree(mutex: Mutex): Promise<MutexInterface.Releaser> | 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<void> {
Expand Down

0 comments on commit 34a7985

Please sign in to comment.