Improve IK-style artifact scanner pipeline
This commit is contained in:
@@ -16,6 +16,8 @@ export interface CardReadyOptions {
|
||||
maxWaitMs?: number;
|
||||
/** Delay between samples. */
|
||||
pollIntervalMs?: number;
|
||||
/** Proceed with changed-but-animated content after this much elapsed time. */
|
||||
acceptChangedAfterMs?: number;
|
||||
}
|
||||
|
||||
export interface CardReadyDeps {
|
||||
@@ -53,6 +55,7 @@ export async function waitForCardReady(
|
||||
const minStable = Math.max(1, options.minStableSamples ?? DEFAULT_MIN_STABLE);
|
||||
const maxWaitMs = Math.max(0, options.maxWaitMs ?? DEFAULT_MAX_WAIT_MS);
|
||||
const pollIntervalMs = Math.max(1, options.pollIntervalMs ?? DEFAULT_POLL_MS);
|
||||
const acceptChangedAfterMs = Math.max(0, options.acceptChangedAfterMs ?? maxWaitMs);
|
||||
|
||||
const start = deps.now();
|
||||
let previousSample = "";
|
||||
@@ -77,11 +80,13 @@ export async function waitForCardReady(
|
||||
const changed = Boolean(latest) && latest !== previousFingerprint;
|
||||
const stable = stableCount >= minStable;
|
||||
|
||||
if (changed && stable) {
|
||||
return { ready: true, changed: true, stable: true, fingerprint: latest, abortReason: "", polls };
|
||||
const elapsedMs = deps.now() - start;
|
||||
|
||||
if (changed && (stable || elapsedMs >= acceptChangedAfterMs)) {
|
||||
return { ready: true, changed: true, stable, fingerprint: latest, abortReason: "", polls };
|
||||
}
|
||||
|
||||
if (deps.now() - start >= maxWaitMs) {
|
||||
if (elapsedMs >= maxWaitMs) {
|
||||
// Budget spent. Proceed if the content has at least changed, even if it is
|
||||
// still animating (never fully stabilizes).
|
||||
return { ready: changed, changed, stable, fingerprint: latest, abortReason: "", polls };
|
||||
|
||||
Reference in New Issue
Block a user