()
| 123 | * Called before normal process exit via `beforeExit`. |
| 124 | */ |
| 125 | export async function flush(): Promise<void> { |
| 126 | const payload = drainQueueToPayload(); |
| 127 | if (payload == null) return; |
| 128 | |
| 129 | const controller = new AbortController(); |
| 130 | const timeout = setTimeout(() => controller.abort(), FLUSH_TIMEOUT_MS); |
| 131 | |
| 132 | try { |
| 133 | await fetch(`${POSTHOG_HOST}/batch/`, { |
| 134 | method: "POST", |
| 135 | headers: { "Content-Type": "application/json", Connection: "close" }, |
| 136 | body: payload, |
| 137 | signal: controller.signal, |
| 138 | }); |
| 139 | } catch { |
| 140 | // Silently ignore — telemetry must never break the CLI |
| 141 | } finally { |
| 142 | clearTimeout(timeout); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Fire-and-forget flush for use in the `exit` event handler. |
nothing calls this directly
no test coverage detected