export declare const enter: unique symbol; export declare const exit: unique symbol; type Result = { value: T; } | { exception: E; }; export declare class EnterException { exception: unknown; constructor(exception: unknown); } export declare class ExitException { exception: unknown; result: Result; constructor(exception: unknown, result: Result); } /** * An object implementing the `Context` interface has some notion of * "being entered" and always eventually "being exited". It should be used * together with the `within` function to enclose a function with a context. * * A "handle" is an object that can only assumed valid while within the * context. It should not be used after the context has exited and doing * so should be treated as undefined behavior. * * The `within` function will: * - call the `enter` method exactly once. * - call the `exit` exactly once and only after `enter` has been called. */ export interface Context { [enter]: () => MaybePromise; [exit]?: (handle: THandle) => MaybePromise; } type ContextResult, TFnResult extends MaybePromise, TExitResult extends MaybePromise> = TFnResult extends PromiseLike ? TFnResult : TEnterResult extends PromiseLike ? PromiseLike : TExitResult extends PromiseLike ? PromiseLike : TFnResult; type MaybePromise = T | PromiseLike; type Resolve> = T extends MaybePromise ? U : T; export declare function within, TFnResult extends MaybePromise, TExitResult extends MaybePromise = void>(context: { [enter]: () => TEnterResult; [exit]?: (handler: Resolve) => TExitResult; }, fn: (handler: Resolve) => TFnResult): ContextResult; export {}; //# sourceMappingURL=context.d.ts.map