这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions workers/loc.api/helpers/get-data-from-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ const {
} = require('./api-errors-testers')

const _delay = (mc = 80000, interrupter) => {
if (_isInterrupted(interrupter)) {
return Promise.resolve({ isInterrupted: true })
}

return new Promise((resolve) => {
const hasInterrupter = interrupter instanceof Interrupter
const timeout = setTimeout(() => {
if (hasInterrupter) {
interrupter.offInterrupt(onceInterruptHandler)
}

resolve()
resolve({ isInterrupted: false })
}, mc)
const onceInterruptHandler = () => {
if (!timeout.hasRef()) {
return
}

clearTimeout(timeout)
resolve()
resolve({ isInterrupted: true })
}

if (hasInterrupter) {
Expand Down Expand Up @@ -116,11 +120,12 @@ module.exports = (
if (countRateLimitError > 100) {
throw err
}
if (_isInterrupted(_interrupter)) {
return { isInterrupted: true }
}

await _delay(ms, _interrupter)
const { isInterrupted } = await _delay(ms, _interrupter)

if (isInterrupted) {
return { isInterrupted }
}

continue
}
Expand All @@ -130,11 +135,12 @@ module.exports = (
if (countNonceSmallError > 20) {
throw err
}
if (_isInterrupted(_interrupter)) {
return { isInterrupted: true }
}

await _delay(1000, _interrupter)
const { isInterrupted } = await _delay(1000, _interrupter)

if (isInterrupted) {
return { isInterrupted }
}

continue
}
Expand All @@ -156,7 +162,13 @@ module.exports = (
await wsEventEmitter.emitENetError(callerName)
}

await _delay(eNetErrorAttemptsTimeoutMs, _interrupter)
const {
isInterrupted
} = await _delay(eNetErrorAttemptsTimeoutMs, _interrupter)

if (isInterrupted) {
return { isInterrupted }
}

continue
}
Expand All @@ -170,11 +182,12 @@ module.exports = (
) {
throw err
}
if (_isInterrupted(_interrupter)) {
return { isInterrupted: true }
}

await _delay(10000, _interrupter)
const { isInterrupted } = await _delay(10000, _interrupter)

if (isInterrupted) {
return { isInterrupted }
}
}
}

Expand Down