puppeteer-core
Version:
A high-level API to control headless Chrome over the DevTools Protocol
47 lines (42 loc) • 979 B
text/typescript
/**
* @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 {
constructor(mutex: Mutex) {
this.
}
[](): void {
return this.
}
};
// This is FIFO.
async acquire(): Promise<InstanceType<typeof Mutex.Guard>> {
if (!this.
this.
return new Mutex.Guard(this);
}
const deferred = Deferred.create<void>();
this.
await deferred.valueOrThrow();
return new Mutex.Guard(this);
}
release(): void {
const resolve = this.
if (!resolve) {
this.
return;
}
resolve();
}
}