Skip to content

Commit 574ff4e

Browse files
authored
refactor: remove onRelease functionality from Mutex (#252)
This PR Fixes #249 The `onRelease` functionality in the `Mutex` class was unused. This change removes the `onRelease` callback from the `acquire` method and the `Guard` class, simplifying the implementation.
1 parent 1b226b8 commit 574ff4e

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

src/Mutex.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
export class Mutex {
88
static Guard = class Guard {
99
#mutex: Mutex;
10-
#onRelease?: () => void;
11-
constructor(mutex: Mutex, onRelease?: () => void) {
10+
constructor(mutex: Mutex) {
1211
this.#mutex = mutex;
13-
this.#onRelease = onRelease;
1412
}
1513
dispose(): void {
16-
this.#onRelease?.();
1714
return this.#mutex.release();
1815
}
1916
};
@@ -22,17 +19,15 @@ export class Mutex {
2219
#acquirers: Array<() => void> = [];
2320

2421
// This is FIFO.
25-
async acquire(
26-
onRelease?: () => void,
27-
): Promise<InstanceType<typeof Mutex.Guard>> {
22+
async acquire(): Promise<InstanceType<typeof Mutex.Guard>> {
2823
if (!this.#locked) {
2924
this.#locked = true;
3025
return new Mutex.Guard(this);
3126
}
3227
const {resolve, promise} = Promise.withResolvers<void>();
3328
this.#acquirers.push(resolve);
3429
await promise;
35-
return new Mutex.Guard(this, onRelease);
30+
return new Mutex.Guard(this);
3631
}
3732

3833
release(): void {

0 commit comments

Comments
 (0)