Sync Construction, Async Property The initialization of the client is synchronous. The async work is stored as a property you can await, while passing the reference around. When to Apply This Pattern Use this when you have: Async client initialization (IndexedDB, server connection, file system) Module exports that need to be importable without await UI components that want sync access to the client SvelteKit apps where you want to gate rendering on readiness Signals you're fighting async construction: await getX() patterns everywhere Top-level await complaints from bundlers Getter functions wrapping singleton access Components that can't import a client directly The Problem Async constructors can't be exported: // This doesn't work export const client = await createClient ( ) ; // Top-level await breaks bundlers So you end up with getter patterns: let client : Client | null = null ; export async function getClient ( ) { if ( ! client ) { client = await createClient ( ) ; } return client ; } // Every consumer must await const client = await getClient ( ) ; Every call site needs await . You're passing promises around instead of objects. The Pattern Make construction synchronous. Attach async work to the object: // client.ts export const client = createClient ( ) ; // Sync access works immediately client . save ( data ) ; client . load ( id ) ; // Await the async work when you need to await client . whenSynced ; Construction returns immediately. The async initialization (loading from disk, connecting to servers) happens in the background and is tracked via whenSynced . The UI Render Gate In Svelte, await once at the root:
{#await client.whenSynced}