ts-raii-scope
Version:
TypeScript RAII proof of concept
22 lines (21 loc) • 771 B
TypeScript
import { IDisposable } from '../types/disposable';
import { RaiiScope } from './raiiScope';
declare class ScopeStack {
protected _syncStack: RaiiScope[];
protected _asyncScopes: Map<RaiiScope, boolean>;
enterScope(isAsync: boolean, scope?: RaiiScope): RaiiScope;
exitScope(scope: RaiiScope): Promise<any> | void;
asyncScopeDone(scope: RaiiScope): Promise<any> | void;
/**
* Call from sync methods
*/
pushToTopScope<T extends IDisposable>(resource: T): T;
/**
* Call inside async method to keep scope in local variable
*/
saveCurrentAsyncScope(): RaiiScope;
protected getTopScope(): RaiiScope;
protected findSyncStackIndex(scope: RaiiScope): number;
}
export declare const scopeStack: ScopeStack;
export {};