@launchmenu/core
Version:
An environment for visual keyboard controlled applets
39 lines • 1.43 kB
TypeScript
import { IDataHook, Field } from "model-react";
export declare class Semaphore {
protected maxConcurrency: number;
protected queue: Array<(lease: [number, () => void]) => void>;
protected currentReleaser: (() => void) | undefined;
protected value: Field<number>;
/**
* Creates a new semaphore
* @param maxConcurrency The maximum concurrency
*/
constructor(maxConcurrency: number);
/**
* Acquires the semaphore
* @returns The number of claims remaining and a function that can be used to release the resource
*/
acquire(): Promise<[number, () => void]>;
/**
* Runs the given function and makes sure to acquire and release the semaphore
* @param callback The callback to run
* @returns The result of the callback
*/
runExclusive<T>(callback: (value: number) => Promise<T> | T): Promise<T>;
/**
* Checks whether the semaphore is locked
* @param hook A hook to subscribe to changes
* @returns Whether the semaphore is locked
*/
isLocked(hook?: IDataHook): boolean;
/**
* Releases the semaphore if locked.
* Only available on semaphores with concurrency = 1.
*/
release(): void;
/**
* Dispatches an update in order to continue with the next consumer if present
*/
protected _dispatch(): void;
}
//# sourceMappingURL=Semaphore.d.ts.map