()
| 846 | // Called after writeBatch completes (or fails) so queued messages |
| 847 | // are sent in order after the historical messages. |
| 848 | function drainFlushGate(): void { |
| 849 | const msgs = flushGate.end() |
| 850 | if (msgs.length === 0) return |
| 851 | if (!transport) { |
| 852 | logForDebugging( |
| 853 | `[bridge:repl] Cannot drain ${msgs.length} pending message(s): no transport`, |
| 854 | ) |
| 855 | return |
| 856 | } |
| 857 | for (const msg of msgs) { |
| 858 | recentPostedUUIDs.add(msg.uuid) |
| 859 | } |
| 860 | const sdkMessages = toSDKMessages(msgs) |
| 861 | const events = sdkMessages.map(sdkMsg => ({ |
| 862 | ...sdkMsg, |
| 863 | session_id: currentSessionId, |
| 864 | })) |
| 865 | logForDebugging( |
| 866 | `[bridge:repl] Drained ${msgs.length} pending message(s) after flush`, |
| 867 | ) |
| 868 | void transport.writeBatch(events) |
| 869 | } |
| 870 | |
| 871 | // Teardown reference — set after definition below. All callers are async |
| 872 | // callbacks that run after assignment, so the reference is always valid. |
no test coverage detected