Skip to content

Commit

Permalink
change logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBonHubspot committed Oct 3, 2023
1 parent a0bb005 commit 6b41483
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/wait-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ function waitFor(
jest.advanceTimersByTime(interval)
})

// Could have timed-out
if (finished) {
break
}
// It's really important that checkCallback is run *before* we flush
// in-flight promises. To be honest, I'm not sure why, and I can't quite
// think of a way to reproduce the problem in a test, but I spent
// an entire day banging my head against a wall on this.
checkCallback()

if (finished) {
break
}
}
} else {
try {
Expand All @@ -106,9 +106,6 @@ function waitFor(
}

function onDone(error, result) {
if (finished) {
return
}
finished = true
clearTimeout(overallTimeoutTimer)

Expand Down Expand Up @@ -137,7 +134,7 @@ function waitFor(
}

function checkCallback() {
if (finished || promiseStatus === 'pending') return
if (promiseStatus === 'pending') return
try {
const result = runWithExpensiveErrorDiagnosticsDisabled(callback)
if (typeof result?.then === 'function') {
Expand All @@ -163,9 +160,6 @@ function waitFor(
}

function handleTimeout() {
if (finished) {
return
}
let error
if (lastError) {
error = lastError
Expand Down

0 comments on commit 6b41483

Please sign in to comment.