Rocky_Mountain_Vending/.pnpm-store/v10/files/f4/362663d4f08b4d588963bfb3494839e530480150cced3938598669f3f0720ab3dea5d43803553800863aebfeed23e2fc4f9a6805b3496254c50c0eb059092e
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

51 lines
1.1 KiB
Text

/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {Deferred} from './Deferred.js';
import {disposeSymbol} from './disposable.js';
/**
* @internal
*/
export class Mutex {
static Guard = class Guard {
#mutex: Mutex;
#onRelease?: () => void;
constructor(mutex: Mutex, onRelease?: () => void) {
this.#mutex = mutex;
this.#onRelease = onRelease;
}
[disposeSymbol](): void {
this.#onRelease?.();
return this.#mutex.release();
}
};
#locked = false;
#acquirers: Array<() => void> = [];
// This is FIFO.
async acquire(
onRelease?: () => void,
): Promise<InstanceType<typeof Mutex.Guard>> {
if (!this.#locked) {
this.#locked = true;
return new Mutex.Guard(this);
}
const deferred = Deferred.create<void>();
this.#acquirers.push(deferred.resolve.bind(deferred));
await deferred.valueOrThrow();
return new Mutex.Guard(this, onRelease);
}
release(): void {
const resolve = this.#acquirers.shift();
if (!resolve) {
this.#locked = false;
return;
}
resolve();
}
}