Fix FSRS progress update issues (#3420)

* Delay optimal FSRS params alert to ensure progress updates are reported

* Ensure progress updates arrive synchronously
This commit is contained in:
Abdo 2024-09-20 14:18:02 +03:00 committed by GitHub
parent cb3a7579de
commit 847f3f6714
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View file

@ -8,13 +8,19 @@ export async function runWithBackendProgress<T>(
callback: () => Promise<T>,
onUpdate: (progress: Progress) => void,
): Promise<T> {
const intervalId = setInterval(async () => {
let done = false;
async function progressCallback() {
const progress = await latestProgress({});
onUpdate(progress);
}, 100);
if (done) {
return;
}
setTimeout(progressCallback, 100);
}
setTimeout(progressCallback, 100);
try {
return await callback();
} finally {
clearInterval(intervalId);
done = true;
}
}

View file

@ -150,7 +150,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
)) ||
resp.weights.length === 0
) {
alert(tr.deckConfigFsrsParamsOptimal());
setTimeout(() => alert(tr.deckConfigFsrsParamsOptimal()), 100);
}
if (computeWeightsProgress) {
computeWeightsProgress.current = computeWeightsProgress.total;