/** * Lifecycle management for resources that need acquisition and cleanup. * * Inspired by distage's Lifecycle feature, this provides automatic resource * management with guaranteed cleanup. * * Example: * const dbLifecycle = Lifecycle.make( * () => connectToDatabase(), // acquire * (db) => db.disconnect() // release * ); */ /** * A resource that needs to be acquired and released/cleaned up. * * The Lifecycle type ensures that resources are properly cleaned up * even if errors occur during usage. */ export declare class Lifecycle { private readonly acquireFn; private readonly releaseFn; constructor(acquireFn: () => T | Promise, releaseFn: (resource: T) => void | Promise); /** * Create a Lifecycle from acquire and release functions */ static make(acquire: () => T | Promise, release: (resource: T) => void | Promise): Lifecycle; /** * Create a Lifecycle from an object with a close() method * (like file handles, database connections, etc.) */ static fromAutoCloseable; }>(acquire: () => T | Promise): Lifecycle; /** * Create a Lifecycle that just wraps a value (no cleanup needed) */ static pure(value: T): Lifecycle; /** * Acquire the resource */ acquire(): Promise; /** * Release/cleanup the resource */ release(resource: T): Promise; /** * Use the resource and automatically clean it up afterwards * * This is the recommended way to use a Lifecycle - it guarantees * cleanup even if an error occurs. */ use(fn: (resource: T) => R | Promise): Promise; /** * Map the resource to a different type */ map(fn: (resource: T) => R | Promise): Lifecycle; /** * Chain two lifecycles together */ flatMap(fn: (resource: T) => Lifecycle): Lifecycle; } /** * Manages multiple Lifecycle resources and ensures they're all released * in reverse order of acquisition (LIFO - Last In, First Out). */ export declare class LifecycleManager { private resources; /** * Acquire a resource and track it for cleanup */ acquire(lifecycle: Lifecycle): Promise; /** * Release all acquired resources in reverse order (LIFO) */ releaseAll(): Promise; /** * Use multiple resources and automatically clean them all up */ use(fn: () => R | Promise): Promise; } /** * Error that aggregates multiple cleanup errors */ export declare class AggregateLifecycleError extends Error { readonly errors: Error[]; constructor(errors: Error[]); } //# sourceMappingURL=Lifecycle.d.ts.map