@mondaycom/apps-cli
Version:
A cli tool to manage apps (and monday-code projects) in monday.com
26 lines (25 loc) • 728 B
JavaScript
import { setTimeout as asyncSetTimeout } from 'node:timers/promises';
const sleep = async (ms) => {
await asyncSetTimeout(ms);
};
export async function pollPromise(fn, delayInMs, timeOutInMs) {
let isTimeOut = false;
let isDone = false;
const setTimeoutId = setTimeout(() => {
isTimeOut = true;
isDone = true;
}, timeOutInMs);
do {
// eslint-disable-next-line no-await-in-loop
isDone = await fn();
if (isDone) {
clearTimeout(setTimeoutId);
return;
}
// eslint-disable-next-line no-await-in-loop
await sleep(delayInMs);
} while (!isDone);
if (isTimeOut) {
throw new Error('Polling timeout.');
}
}