/** * =============================================================================== * SINGLETON PATTERN UTILITIES * =============================================================================== * * Reusable singleton pattern implementation to reduce boilerplate. * Used across: HookRegistry, SymbolManager, etc. * * Usage: * const [getInstance, resetInstance] = createSingleton(() => new MyClass()); * export { getInstance as getMyClass, resetInstance as resetMyClass }; * * =============================================================================== */ /** * Creates a singleton factory with lazy initialization. * * @param factory - Function that creates the singleton instance * @returns Tuple of [getInstance, resetInstance] functions * * @example * ```typescript * class DatabaseConnection { * constructor(private config: Config) {} * } * * const [getDb, resetDb] = createSingleton(() => new DatabaseConnection(loadConfig())); * export { getDb as getDatabaseConnection }; * ``` */ export declare function createSingleton(factory: () => T): [() => T, () => void]; /** * Creates a singleton factory with async initialization. * * @param factory - Async function that creates the singleton instance * @returns Tuple of [getInstance, resetInstance] functions * * @example * ```typescript * const [getDb, resetDb] = createAsyncSingleton(async () => { * const db = new Database(); * await db.connect(); * return db; * }); * ``` */ export declare function createAsyncSingleton(factory: () => Promise): [() => Promise, () => void]; /** * Creates a singleton with configurable initialization. * Allows passing configuration on first call. * * @param factory - Function that creates the instance with config * @returns Tuple of [getInstance, resetInstance] functions * * @example * ```typescript * const [getServer, resetServer] = createConfigurableSingleton( * (config: ServerConfig) => new Server(config) * ); * * // First call initializes with config * const server = getServer({ port: 3000 }); * * // Subsequent calls return same instance (config ignored) * const sameServer = getServer({ port: 4000 }); // Returns 3000 server * ``` */ export declare function createConfigurableSingleton(factory: (config: C) => T): [(config: C) => T, () => void]; //# sourceMappingURL=singleton.d.ts.map