mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
27 lines
487 B
JavaScript
27 lines
487 B
JavaScript
/** @babel */
|
|
|
|
export async function conditionPromise (
|
|
condition,
|
|
description = 'anonymous condition'
|
|
) {
|
|
const startTime = Date.now()
|
|
|
|
while (true) {
|
|
await timeoutPromise(100)
|
|
|
|
if (await condition()) {
|
|
return
|
|
}
|
|
|
|
if (Date.now() - startTime > 5000) {
|
|
throw new Error('Timed out waiting on ' + description)
|
|
}
|
|
}
|
|
}
|
|
|
|
export function timeoutPromise (timeout) {
|
|
return new Promise(function (resolve) {
|
|
global.setTimeout(resolve, timeout)
|
|
})
|
|
}
|