( queueMap: Map<string, Promise<void>>, key: string, operation: () => Promise<void>, )
| 9 | * the chain alive for subsequent writes. |
| 10 | */ |
| 11 | export function chainWrite( |
| 12 | queueMap: Map<string, Promise<void>>, |
| 13 | key: string, |
| 14 | operation: () => Promise<void>, |
| 15 | ): Promise<void> { |
| 16 | const previous = queueMap.get(key) ?? Promise.resolve(); |
| 17 | const next = previous.then(operation, operation); |
| 18 | const stored = next.catch(() => { |
| 19 | // Keep the chain alive after failures. |
| 20 | }); |
| 21 | const tracked = stored.finally(() => { |
| 22 | if (queueMap.get(key) === tracked) queueMap.delete(key); |
| 23 | }); |
| 24 | queueMap.set(key, tracked); |
| 25 | return next; |
| 26 | } |
no test coverage detected