/** Memoized async connection. Concurrent ensure calls share the same in-flight promise. */ export interface LazySession { /** Returns the memoized promise, creating it via `factory()` on first call. */ ensure(): Promise; } export function createLazySession(factory: () => Promise): LazySession { let promise: Promise | null = null; return { ensure(): Promise { promise ??= factory(); return promise; }, }; }