/** * Bounds boot-time async work. Some of it (OAuth client init, metadata * fetch) touches IndexedDB and the network and can stall in odd browser * contexts. A bounded init that degrades to guest mode beats an app that * never opens. */ export function withTimeout(promise: Promise, ms: number, label: string): Promise { return new Promise((resolve, reject) => { const timer = setTimeout(() => { reject(new Error(`${label} timed out after ${ms}ms`)); }, ms); promise.then( (value) => { clearTimeout(timer); resolve(value); }, (reason) => { clearTimeout(timer); reject(reason); }, ); }); }