diff --git a/src/lanes.ts b/src/lanes.ts index 28cfb15..e267f10 100644 --- a/src/lanes.ts +++ b/src/lanes.ts @@ -36,15 +36,18 @@ export class LaneManager { const inflight = this.creating.get(key); if (inflight) return inflight; const promise = (async () => { - const session = await createSession( - this.deps, - { defaultDestination: key, defaultUserId: userId }, - this.client - ); - const lane: Lane = { session }; - this.lanes.set(key, lane); - this.creating.delete(key); - return lane; + try { + const session = await createSession( + this.deps, + { defaultDestination: key, defaultUserId: userId }, + this.client + ); + const lane: Lane = { session }; + this.lanes.set(key, lane); + return lane; + } finally { + this.creating.delete(key); + } })(); this.creating.set(key, promise); return promise;