@bigmi/core
Version:
TypeScript library for Bitcoin apps.
25 lines • 907 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.retryUntil = retryUntil;
const withRetry_js_1 = require("./withRetry.js");
async function retryUntil(condition, options = {}) {
const { timeout = 5000, interval = 100 } = options;
const retryCount = Math.ceil(timeout / interval) - 1;
return Promise.race([
(0, withRetry_js_1.withRetry)(async () => {
const result = await condition();
if (!result) {
throw new Error('Condition not met');
}
return result;
}, {
delay: interval,
retryCount,
shouldRetry: ({ error }) => error.message === 'Condition not met',
}).catch(() => undefined),
new Promise((resolve) => {
setTimeout(() => resolve(undefined), timeout);
}),
]);
}
//# sourceMappingURL=retryUntil.js.map