Merge pull request #74 from joenunezb/fix/hanging-swipes-with-chapterCheckpoints
fix: Swipes hanging due race condition when handling promises in chapterCheckpoints
This commit is contained in:
@@ -14,6 +14,7 @@ let currentlyHiddenRange = null;
|
||||
// Debounce restore to prevent loops
|
||||
let isRestoring = false;
|
||||
let restoreTimeout = null;
|
||||
let pendingResolve = null;
|
||||
|
||||
/**
|
||||
* Gets the current chapter checkpoint message ID for the active chat
|
||||
@@ -129,13 +130,19 @@ export async function restoreCheckpointOnLoad() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear any pending timeout
|
||||
// Clear any pending timeout and resolve the pending promise
|
||||
if (restoreTimeout) {
|
||||
clearTimeout(restoreTimeout);
|
||||
restoreTimeout = null;
|
||||
}
|
||||
if (pendingResolve) {
|
||||
pendingResolve();
|
||||
pendingResolve = null;
|
||||
}
|
||||
|
||||
// Debounce: wait 100ms before actually restoring
|
||||
return new Promise((resolve) => {
|
||||
pendingResolve = resolve;
|
||||
restoreTimeout = setTimeout(async () => {
|
||||
isRestoring = true;
|
||||
try {
|
||||
@@ -174,6 +181,7 @@ export async function restoreCheckpointOnLoad() {
|
||||
}
|
||||
} finally {
|
||||
isRestoring = false;
|
||||
pendingResolve = null;
|
||||
resolve();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
Reference in New Issue
Block a user