mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
15 lines
491 B
TypeScript
15 lines
491 B
TypeScript
export async function waitUntil(condition: () => boolean, timeout = 1000) {
|
|
return new Promise((resolve, reject) => {
|
|
const start = Date.now();
|
|
const interval = setInterval(() => {
|
|
if (condition()) {
|
|
clearInterval(interval);
|
|
resolve(undefined);
|
|
} else if (Date.now() - start > timeout) {
|
|
clearInterval(interval);
|
|
reject(new Error('Timeout'));
|
|
}
|
|
}, 10);
|
|
});
|
|
}
|