Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Aug 21, 2024
1 parent c6eeb09 commit 8ec6c9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it('should allow only one lock at a time', async ({ expect }) => {
// second lock shouldnt resolve
await expect(Promise.race([throwAfter(50), lock2])).rejects.toBeTruthy();

unlock1();
await unlock1();

// after the first lock releases, second one resolves
await expect(lock2).resolves.toBeTruthy();
Expand Down Expand Up @@ -97,7 +97,7 @@ it('should keep auto-extending lock until unlock', async ({ expect }) => {
// second lock still cannot be acquired resolve
await expect(Promise.race([throwAfter(50), lock2])).rejects.toBeTruthy();

unlock();
await unlock();

// only after unlock can the second lock be acquired
await expect(lock2).resolves.toBeTruthy();
Expand Down
11 changes: 7 additions & 4 deletions packages/services/api/src/modules/shared/providers/mutex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ export class Mutex {
// we have a global timeout of 90 seconds to avoid dead-licks
const globalTimeout = setTimeout(() => {
logger.error('Global lock timeout exceeded (id=%s)', id);
cleanup();
void cleanup();
}, 90_000);

/** cleanup timers and release the lock. */
async function cleanup() {
function cleanup() {
if (extendTimeout === undefined) {
return;
}
Expand All @@ -146,7 +146,10 @@ export class Mutex {

extendTimeout = undefined;
if (lock.expiration > new Date().getTime()) {
await lock.release();
void lock.release().catch(err => {
logger.error('Failed to release lock (id=%s)', id);
console.error(err);
});
}
}

Expand All @@ -169,7 +172,7 @@ export class Mutex {

logger.debug('Lock acquired (id=%s)', id);

extendLock(true);
await extendLock(true);

return cleanup;
}
Expand Down

0 comments on commit 8ec6c9a

Please sign in to comment.