From a4d99aae254cd4c75ac9ea7fd255d6f172ee1792 Mon Sep 17 00:00:00 2001 From: mithun50 Date: Thu, 2 Oct 2025 15:54:29 +0530 Subject: [PATCH 1/2] Refactor: Remove onRelease functionality from Mutex --- src/Mutex.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Mutex.ts b/src/Mutex.ts index 78c01633..c5de4bca 100644 --- a/src/Mutex.ts +++ b/src/Mutex.ts @@ -7,13 +7,10 @@ export class Mutex { static Guard = class Guard { #mutex: Mutex; - #onRelease?: () => void; - constructor(mutex: Mutex, onRelease?: () => void) { + constructor(mutex: Mutex) { this.#mutex = mutex; - this.#onRelease = onRelease; } dispose(): void { - this.#onRelease?.(); return this.#mutex.release(); } }; @@ -22,9 +19,7 @@ export class Mutex { #acquirers: Array<() => void> = []; // This is FIFO. - async acquire( - onRelease?: () => void, - ): Promise> { + async acquire(): Promise> { if (!this.#locked) { this.#locked = true; return new Mutex.Guard(this); @@ -32,7 +27,7 @@ export class Mutex { const {resolve, promise} = Promise.withResolvers(); this.#acquirers.push(resolve); await promise; - return new Mutex.Guard(this, onRelease); + return new Mutex.Guard(this); } release(): void { @@ -44,3 +39,4 @@ export class Mutex { resolve(); } } + From 222917b2487d567cb6fc7ee14b6901ce830cc0f1 Mon Sep 17 00:00:00 2001 From: mithun50 Date: Thu, 2 Oct 2025 16:58:30 +0530 Subject: [PATCH 2/2] Fix Mutex formatting and update docs --- src/Mutex.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Mutex.ts b/src/Mutex.ts index c5de4bca..b66e0cd2 100644 --- a/src/Mutex.ts +++ b/src/Mutex.ts @@ -39,4 +39,3 @@ export class Mutex { resolve(); } } -