Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _unlock(handle: LockHandle) {
if (this._handle !== handle) {
throw new Error("Lock already released.");
}
if (!this._waiters.resolveOne()) {
this._handle = undefined;
}
}
// #region AsyncLockable
[AsyncLockable.lock](cancelable?: Cancelable) {
return this.lock(cancelable);
}
[AsyncLockable.unlock]() {
this.unlock();
}
// #endregion AsyncLockable
}
const disposablePrototype: object = Object.getPrototypeOf(Disposable.create(() => {}));
const mutexLockHandlePrototype: object = {
[AsyncLockable.lock](this: LockHandle, cancelable?: Cancelable) {
return this.lock(cancelable);
},
[AsyncLockable.unlock](this: LockHandle) {
return this.unlock();
},
[Disposable.dispose](this: LockHandle) {
if (this.ownsLock) {
import { Cancelable } from "@esfx/cancelable";
import { Disposable } from "@esfx/disposable";
export { LockHandle, UpgradeableLockHandle } from "@esfx/async-lockable";
const disposablePrototype: object = Object.getPrototypeOf(Disposable.create(() => { }));
const lockHandlePrototype: object = {
get mutex() {
return this;
},
async [AsyncLockable.lock](this: LockHandle, cancelable?: Cancelable) {
await this.lock(cancelable);
return this;
},
[AsyncLockable.unlock](this: LockHandle) {
this.unlock();
},
[Disposable.dispose](this: LockHandle) {
if (this.ownsLock) {
this.unlock();
}
}
};
defineTag(lockHandlePrototype, "LockHandle");
Object.setPrototypeOf(lockHandlePrototype, disposablePrototype);
const readerPrototype: object = {};
defineTag(readerPrototype, "AsyncReaderWriterLockReader");
Object.setPrototypeOf(readerPrototype, lockHandlePrototype);