mirror of
https://github.com/lana-k/sqliteviz.git
synced 2026-02-04 07:28:55 +08:00
21 lines
479 B
JavaScript
21 lines
479 B
JavaScript
export function waitCondition(condition, timeoutMs = 5000) {
|
|
return new Promise((resolve, reject) => {
|
|
if (condition()) {
|
|
resolve()
|
|
return
|
|
}
|
|
const start = new Date().getTime()
|
|
const interval = setInterval(() => {
|
|
if (condition()) {
|
|
clearInterval(interval)
|
|
resolve()
|
|
} else {
|
|
if (new Date().getTime() - start > timeoutMs) {
|
|
clearInterval(interval)
|
|
reject()
|
|
}
|
|
}
|
|
}, 500)
|
|
})
|
|
}
|