How to use @esfx/async-lockable - 4 common examples

To help you get started, we’ve selected a few @esfx/async-lockable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github esfx / esfx / packages / async-mutex / src / index.ts View on Github external
// #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) {
            this.unlock();
        }
    }
};

defineTag(mutexLockHandlePrototype, "MutexLockHandle");
Object.setPrototypeOf(mutexLockHandlePrototype, disposablePrototype);

function createLockHandle(mutex: AsyncMutex): LockHandle {
github esfx / esfx / packages / async-mutex / src / index.ts View on Github external
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) {
github esfx / esfx / packages / async-readerwriterlock / src / index.ts View on Github external
import { Tag, defineTag } from "@esfx/internal-tag";
import { WaitQueue } from "@esfx/async-waitqueue";
import { LockHandle, UpgradeableLockHandle, AsyncLockable } from "@esfx/async-lockable";
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);
github esfx / esfx / packages / async-readerwriterlock / src / index.ts View on Github external
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);

@esfx/async-lockable

A low-level Symbol-based common API for async coordination primitives.

Apache-2.0
Latest version published 2 years ago

Package Health Score

48 / 100
Full package analysis

Similar packages