Add fallback counter

This commit is contained in:
awsr
2026-02-12 14:24:17 -08:00
parent 43f134d9f9
commit 792d2a4d99
+22 -2
View File
@@ -8,7 +8,6 @@ let outstanding = 0;
let lastSort = 0;
let lastSortName = 'None';
let gallerySelection = { files: [], index: -1 };
const galleryHashes = new Set();
let maintenanceController = new AbortController();
const folderStylesheet = new CSSStyleSheet();
const fileStylesheet = new CSSStyleSheet();
@@ -111,7 +110,8 @@ async function awaitForOutstanding(num, signal) {
* @param {AbortSignal} signal - AbortController signal
*/
async function awaitForGallery(expectedSize, signal) {
while (galleryHashes.size < expectedSize && !signal.aborted) await new Promise((resolve) => { setTimeout(resolve, 500); }); // longer interval because it's a low priority check
// eslint-disable-next-line no-use-before-define
while (Math.max(galleryHashes.size, galleryHashes.fallback) < expectedSize && !signal.aborted) await new Promise((resolve) => { setTimeout(resolve, 500); }); // longer interval because it's a low priority check
signal.throwIfAborted();
}
@@ -185,6 +185,26 @@ function updateGalleryStyles() {
// Classes
class HashSet extends Set {
constructor(val) {
super(val);
// Using a variable to store a counter has sometimes been unreliable in the past
this.fallback = 0;
}
add(value) {
++this.fallback;
super.add(value);
}
clear() {
this.fallback = 0;
super.clear();
}
}
const galleryHashes = new HashSet();
class SimpleProgressBar {
#container = document.createElement('div');
#progress = document.createElement('div');