* Create and manage a request with cleanup
( key: string, requestFn: () => Promise<T>, ttl: number )
| 31 | * Create and manage a request with cleanup |
| 32 | */ |
| 33 | private async createRequest<T>( |
| 34 | key: string, |
| 35 | requestFn: () => Promise<T>, |
| 36 | ttl: number |
| 37 | ): Promise<T> { |
| 38 | try { |
| 39 | const result = await requestFn(); |
| 40 | |
| 41 | // Schedule cleanup after TTL |
| 42 | const timeout = window.setTimeout(() => { |
| 43 | this.inFlightRequests.delete(key); |
| 44 | this.activeTimeouts.delete(timeout); |
| 45 | }, ttl); |
| 46 | this.activeTimeouts.add(timeout); |
| 47 | |
| 48 | return result; |
| 49 | } catch (error) { |
| 50 | // Remove failed request immediately |
| 51 | this.inFlightRequests.delete(key); |
| 52 | throw error; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Prefetch data that might be needed soon |
no test coverage detected