Rocky_Mountain_Vending/.pnpm-store/v10/files/f6/17646b3336259cce05a4abe349f72ae71f7f8ba9f742dd99dfa567f69338932c5960c5a35cbaa7d46074b22f37aa18014e19d65a0e08a1ee2c0647963521a8
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

46 lines
No EOL
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;
#onRelease;
constructor(mutex, onRelease) {
this.#mutex = mutex;
this.#onRelease = onRelease;
}
[disposeSymbol]() {
this.#onRelease?.();
return this.#mutex.release();
}
};
#locked = false;
#acquirers = [];
// This is FIFO.
async acquire(onRelease) {
if (!this.#locked) {
this.#locked = true;
return new Mutex.Guard(this);
}
const deferred = Deferred.create();
this.#acquirers.push(deferred.resolve.bind(deferred));
await deferred.valueOrThrow();
return new Mutex.Guard(this, onRelease);
}
release() {
const resolve = this.#acquirers.shift();
if (!resolve) {
this.#locked = false;
return;
}
resolve();
}
}
//# sourceMappingURL=Mutex.js.map