Merge pull request #1829 from cheahjs/fix/fluid-streaming-background

fix: fluid streaming was "pausing" when tab was not visible
This commit is contained in:
Timothy Jaeryang Baek 2024-04-28 10:24:30 -07:00 committed by GitHub
commit 9ddc243c52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -73,7 +73,11 @@ async function* streamLargeDeltasAsRandomChunks(
const chunkSize = Math.min(Math.floor(Math.random() * 3) + 1, content.length); const chunkSize = Math.min(Math.floor(Math.random() * 3) + 1, content.length);
const chunk = content.slice(0, chunkSize); const chunk = content.slice(0, chunkSize);
yield { done: false, value: chunk }; yield { done: false, value: chunk };
await sleep(5); // Do not sleep if the tab is hidden
// Timers are throttled to 1s in hidden tabs
if (document?.visibilityState !== 'hidden') {
await sleep(5);
}
content = content.slice(chunkSize); content = content.slice(chunkSize);
} }
} }