UNPKG

rvx

Version:

A signal based rendering library

55 lines (54 loc) 2.33 kB
export { LeakHook, onLeak } from "./internals/stacks.js"; /** * A function that is called to dispose something. */ export type TeardownHook = () => void; /** * Run a function while capturing teardown hooks. * * + If an error is thrown by the specified function, teardown hooks are called in reverse registration order and the error is re-thrown. * + If an error is thrown by a teardown hook, remaining ones are not called and the error is re-thrown. * * @param fn The function to run. * @returns A function to run all captured teardown hooks in reverse registration order. */ export declare function capture(fn: () => void): TeardownHook; /** * Run a function while capturing teardown hooks. * * + When disposed before the specified function finishes, teardown hooks are called in reverse registration order immediately after the function finishes. * + If an error is thrown by the specified function, teardown hooks are called in reverse registration order and the error is re-thrown. * + If an error is thrown by a teardown hook, remaining ones are not called and the error is re-thrown. * * @param fn The function to run. * @returns The function's return value. */ export declare function captureSelf<T>(fn: (dispose: TeardownHook) => T): T; /** * Run a function without capturing any teardown hooks. * * This is the opposite of {@link capture}. * * @param fn The function to run. * @returns The function's return value. */ export declare function uncapture<T>(fn: () => T): T; /** * Run a function and immediately call teardown hooks if it throws an error. * * + If an error is thrown, teardown hooks are immediately called in reverse registration order and the error is re-thrown. * + If no error is thrown, teardown hooks are registered in the outer context. * * @param fn The function to run. * @returns The function's return value. */ export declare function teardownOnError<T>(fn: () => T): T; /** * Register a teardown hook to be called when the current lifecycle is disposed. * * This has no effect if teardown hooks are not captured in the current context. * * @param hook The hook to register. This may be called multiple times. * @throws An error if teardown hooks are {@link nocapture explicitly un-supported}. */ export declare function teardown(hook: TeardownHook): void;