async-monitor
Version:
Provides a mechanism that synchronizes access to objects.
52 lines (51 loc) • 2.2 kB
TypeScript
/// <reference types="node" />
import { type MapKey } from "../type/map";
import { Monitor } from "./monitor";
export declare class InnerCriticalSection implements Disposable {
readonly parent: InnerCriticalSection;
readonly root: CriticalSectionRoot;
private constructor();
private acquireMonitor;
private assertDeprecateCriticalSection;
private assertMismatchCriticalSectionError;
static create<M extends Monitor>(monitor: M, root: CriticalSectionRoot): InnerCriticalSection;
pulse(): void;
pulseAll(): void;
reenter(abortSignal?: AbortSignal | null): Promise<InnerCriticalSection>;
private releaseMonitor;
[Symbol.dispose](): void;
wait(readyTimeout?: number): Promise<boolean>;
get hasMonitor(): boolean;
get isExited(): boolean;
private readonly exitController;
private readonly monitorChannel;
}
export declare class CriticalSectionRoot {
private readonly key;
constructor(key: MapKey);
static enter<T>(key: MapKey, scope: (criticalSection: CriticalSection) => Promise<T> | T): Promise<T>;
exit(exit: () => InnerCriticalSection): void;
static tryEnter<T>(key: MapKey, timeout: number, scope: (criticalSection: CriticalSection | null) => Promise<T> | T): Promise<T>;
tryEnter(enter: () => Promise<InnerCriticalSection>): Promise<InnerCriticalSection>;
private static tryEnterWithoutScope;
static tryGet(key: MapKey): CriticalSection | null;
get current(): InnerCriticalSection;
private readonly localStorage;
private static readonly map;
private referenceCount;
readonly top: InnerCriticalSection;
}
export interface CriticalSection extends Disposable {
/**
* Notifies a CriticalSection in the waiting queue of a change in the locked key's state.
*/
pulse: () => void;
/**
* Notifies all waiting CriticalSections of a change in the key's state.
*/
pulseAll: () => void;
/**
* Releases the lock on an key and blocks the current CriticalSection until it reacquires the lock. If the specified time-out interval elapses, the CriticalSection enters the ready queue.
*/
wait: (readyTimeout?: number) => Promise<boolean>;
}