fix(sync): keep saving laps from a background Race Day tab so overlays don't freeze (1.89.3)
This commit is contained in:
1 parent
dd2fc6bd89
commit
f5ff1b9acd
7 files changed
+69
-9
No files matched your search
+23
-3
@@ -200,9 +200,29 @@ export async function hydrateFromBackendHelper({ backend, t, getBackendUrl, appl
|
||||
}
|
||||
}
|
||||
|
||||
export function scheduleBackendSyncHelper({ getBackendSyncTimer, setBackendSyncTimer, syncStateToBackend }) {
|
||||
clearTimeout(getBackendSyncTimer());
|
||||
setBackendSyncTimer(setTimeout(() => { syncStateToBackend(); }, 350));
|
||||
// Saves from Race Day to the server. A save waits a moment so a burst of changes goes in one
|
||||
// write, but a new change never pushes a waiting save further back: in a background tab Chrome
|
||||
// runs timers about once a minute, and with a passing every few seconds a reset timer would
|
||||
// never fire - the overlays would freeze. A hidden tab saves straight away instead, one write
|
||||
// at a time, so an older copy can never land after a newer one.
|
||||
export function createBackendSyncScheduler({ sync, isHidden = () => false, delayMs = 350, setTimer = setTimeout, clearTimer = clearTimeout }) {
|
||||
let timer = null;
|
||||
let inFlight = false;
|
||||
let again = false;
|
||||
function run() {
|
||||
if (timer) { clearTimer(timer); timer = null; }
|
||||
if (inFlight) { again = true; return; }
|
||||
inFlight = true;
|
||||
Promise.resolve().then(sync).catch(() => {}).finally(() => {
|
||||
inFlight = false;
|
||||
if (again) { again = false; run(); }
|
||||
});
|
||||
}
|
||||
return function schedule() {
|
||||
if (isHidden()) { run(); return; }
|
||||
if (timer) return;
|
||||
timer = setTimer(() => { timer = null; run(); }, delayMs);
|
||||
};
|
||||
}
|
||||
|
||||
export async function syncStateToBackendHelper({ backend, t, getBackendUrl, buildPersistableState, getLocalStateVersion, getSyncedStateVersion, setSyncedStateVersion, setLocalStateDirty }) {
|
||||
|
||||
Reference in new issue
Block a user