/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import { type IDisposeStrategy } from "./DisposeStrategy"; export interface ResourceScopeOptions { /** Disposal policy. Defaults to {@link DisposeStrategy.runCompletion}. */ strategy?: IDisposeStrategy; } /** * A keyed collection of async disposer functions for heavyweight resources. * * Task authors register disposers during execution. The owning runner calls * `runComplete()` in its `finally` block; the configured * {@link IDisposeStrategy} decides what that means. `dispose(key)` and * `disposeAll()` remain immediate-disposal escape hatches that bypass the * strategy. * * First-registration-wins: if a key is already present, subsequent * registrations for that key are silently ignored. */ export declare class ResourceScope { private readonly disposers; private readonly strategy; constructor(options?: ResourceScopeOptions); /** * Register a disposer under the given key. * If the key already exists, the call is a no-op (first registration wins). */ register(key: string, disposer: () => Promise): void; /** * Signal to the strategy that a resource is still in use (resets inactivity * timers, etc.). No-op under the default {@link RunCompletionStrategy}. */ touch(key: string): void; /** * Call and remove the disposer for the given key (escape hatch — bypasses * the strategy). No-op if the key does not exist. Errors propagate. */ dispose(key: string): Promise; /** * Call all disposers via Promise.allSettled (best-effort), then clear * (escape hatch — bypasses the strategy). Individual disposer errors are * silently swallowed. */ disposeAll(): Promise; /** * Called by runners just before a new run begins. Delegates to the * strategy's optional `onRunStart` hook (no-op when the strategy does * not implement it). Closes the race where an inactivity timer armed * by the previous `runComplete` could fire and dispose a resource the * next run is about to use. * * The guard is load-bearing: it keeps runStart synchronous for strategies * without pre-run work, which preserves the microtask ordering that the * task runner's abort-during-handleStart code path depends on. */ runStart(): Promise; /** * Called by runners' `finally` blocks. Delegates to the strategy's * `onRunComplete` hook. */ runComplete(): Promise; /** Check if a key is registered. */ has(key: string): boolean; /** Iterate registered keys. */ keys(): IterableIterator; /** Number of registered disposers. */ get size(): number; /** Support `await using scope = new ResourceScope()`. Delegates to strategy. */ [Symbol.asyncDispose](): Promise; } //# sourceMappingURL=ResourceScope.d.ts.map