Files
klz-cables.com/.pnpm-store/v10/files/4e/5c678c2d93a594478d1a9954464bc567f5f87d85cd135d006de3b476919e7e1e5633b5ea5c9d5b2a8258e59c34c6e98e5d37fe45f658462698245d10ab02fc
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

62 lines
1.5 KiB
Plaintext

'use strict'
const MAX_TIMEOUT = 1000
function wait (state, index, expected, timeout, done) {
const max = Date.now() + timeout
let current = Atomics.load(state, index)
if (current === expected) {
done(null, 'ok')
return
}
let prior = current
const check = (backoff) => {
if (Date.now() > max) {
done(null, 'timed-out')
} else {
setTimeout(() => {
prior = current
current = Atomics.load(state, index)
if (current === prior) {
check(backoff >= MAX_TIMEOUT ? MAX_TIMEOUT : backoff * 2)
} else {
if (current === expected) done(null, 'ok')
else done(null, 'not-equal')
}
}, backoff)
}
}
check(1)
}
// let waitDiffCount = 0
function waitDiff (state, index, expected, timeout, done) {
// const id = waitDiffCount++
// process._rawDebug(`>>> waitDiff ${id}`)
const max = Date.now() + timeout
let current = Atomics.load(state, index)
if (current !== expected) {
done(null, 'ok')
return
}
const check = (backoff) => {
// process._rawDebug(`${id} ${index} current ${current} expected ${expected}`)
// process._rawDebug('' + backoff)
if (Date.now() > max) {
done(null, 'timed-out')
} else {
setTimeout(() => {
current = Atomics.load(state, index)
if (current !== expected) {
done(null, 'ok')
} else {
check(backoff >= MAX_TIMEOUT ? MAX_TIMEOUT : backoff * 2)
}
}, backoff)
}
}
check(1)
}
module.exports = { wait, waitDiff }