(delay: number)
| 95 | } |
| 96 | |
| 97 | function flushIn(delay: number): void { |
| 98 | if (flushTimer) { |
| 99 | clearTimeout(flushTimer as ReturnType<typeof setTimeout>); |
| 100 | } |
| 101 | |
| 102 | // We need to unref the timer in node.js, otherwise the node process never exit. |
| 103 | flushTimer = safeUnref( |
| 104 | setTimeout(async () => { |
| 105 | flushTimer = undefined; |
| 106 | |
| 107 | const found = await store.shift(); |
| 108 | if (found) { |
| 109 | log('Attempting to send previously queued event'); |
| 110 | |
| 111 | // We should to update the sent_at timestamp to the current time. |
| 112 | found[0].sent_at = new Date(safeDateNow()).toISOString(); |
| 113 | |
| 114 | void send(found, true).catch(e => { |
| 115 | log('Failed to retry sending', e); |
| 116 | }); |
| 117 | } |
| 118 | }, delay), |
| 119 | ) as Timer; |
| 120 | } |
| 121 | |
| 122 | function flushWithBackOff(): void { |
| 123 | if (flushTimer) { |
no test coverage detected