mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
18 lines
387 B
TypeScript
18 lines
387 B
TypeScript
|
export const retry = (assertion: () => any, { interval = 20, timeout = 200 } = {}) => {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
const startTime = Date.now();
|
||
|
|
||
|
const tryAgain = () => {
|
||
|
setTimeout(() => {
|
||
|
try {
|
||
|
resolve(assertion());
|
||
|
} catch (err) {
|
||
|
Date.now() - startTime > timeout ? reject(err) : tryAgain();
|
||
|
}
|
||
|
}, interval);
|
||
|
};
|
||
|
|
||
|
tryAgain();
|
||
|
});
|
||
|
};
|