Buckets:
| 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 } | |
Xet Storage Details
- Size:
- 1.56 kB
- Xet hash:
- 527f09cdb033c6c88177d2b65048f665b7f61c7fc1783de1c7e6dc1cc45a8188
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.