[fix](trx-frontend-http): flush live decode buffer only after history drain completes
drainDecodeHistory() chunks work via setTimeout but flushLiveBuffer() was called synchronously right after starting the drain, so live messages could interleave with in-progress history chunks. Pass flushLiveBuffer as an onDone callback so live messages are only dispatched once all history chunks have been processed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -6162,11 +6162,15 @@ function dispatchDecodeMessage(msg) {
|
||||
if (msg.type === "wspr" && window.onServerWspr) window.onServerWspr(msg);
|
||||
}
|
||||
|
||||
function drainDecodeHistory(buffer, index) {
|
||||
function drainDecodeHistory(buffer, index, onDone) {
|
||||
const CHUNK = 30;
|
||||
const end = Math.min(index + CHUNK, buffer.length);
|
||||
for (let i = index; i < end; i++) dispatchDecodeMessage(buffer[i]);
|
||||
if (end < buffer.length) setTimeout(() => drainDecodeHistory(buffer, end), 0);
|
||||
if (end < buffer.length) {
|
||||
setTimeout(() => drainDecodeHistory(buffer, end, onDone), 0);
|
||||
} else if (typeof onDone === "function") {
|
||||
onDone();
|
||||
}
|
||||
}
|
||||
|
||||
function connectDecode() {
|
||||
@@ -6224,8 +6228,11 @@ function connectDecode() {
|
||||
return resp.json();
|
||||
}).then((msgs) => {
|
||||
clearTimeout(historyTimeout);
|
||||
if (Array.isArray(msgs)) drainDecodeHistory(msgs, 0);
|
||||
flushLiveBuffer();
|
||||
if (Array.isArray(msgs) && msgs.length > 0) {
|
||||
drainDecodeHistory(msgs, 0, flushLiveBuffer);
|
||||
} else {
|
||||
flushLiveBuffer();
|
||||
}
|
||||
}).catch(() => { clearTimeout(historyTimeout); flushLiveBuffer(); });
|
||||
}
|
||||
if (document.readyState === "complete") {
|
||||
|
||||
Reference in New Issue
Block a user