(key: TKey)
| 109 | } |
| 110 | |
| 111 | async function flush(key: TKey): Promise<void> { |
| 112 | const timer = timers.get(key) |
| 113 | if (timer) { |
| 114 | clearTimeout(timer) |
| 115 | timers.delete(key) |
| 116 | } |
| 117 | |
| 118 | const inflight = writing.get(key) |
| 119 | if (inflight) { |
| 120 | await inflight |
| 121 | } |
| 122 | |
| 123 | const task = pending.get(key) |
| 124 | if (!task) return |
| 125 | |
| 126 | pending.delete(key) |
| 127 | firstQueueTime.delete(key) |
| 128 | |
| 129 | const writePromise = retryWithBackoff( |
| 130 | () => persistFn(key, task.data), |
| 131 | maxRetries, |
| 132 | initialRetryDelay, |
| 133 | `persist ${key}` |
| 134 | ) |
| 135 | |
| 136 | writing.set(key, writePromise) |
| 137 | try { |
| 138 | await writePromise |
| 139 | } finally { |
| 140 | writing.delete(key) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | async function flushAll(): Promise<void> { |
| 145 | const keys = Array.from(pending.keys()) |
no test coverage detected