@openocean.finance/widget-sdk
Version:
OpenOcean Any-to-Any Cross-Chain-Swap SDK
29 lines • 856 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForResult = void 0;
const sleep_js_1 = require("./sleep.js");
const waitForResult = async (fn, interval = 5000, maxRetries = 3, shouldRetry = () => true) => {
let result;
let attempts = 0;
while (!result) {
try {
result = await fn();
if (!result) {
await (0, sleep_js_1.sleep)(interval);
}
}
catch (error) {
if (!shouldRetry(attempts, error)) {
throw error;
}
attempts++;
if (attempts === maxRetries) {
throw error;
}
await (0, sleep_js_1.sleep)(interval);
}
}
return result;
};
exports.waitForResult = waitForResult;
//# sourceMappingURL=waitForResult.js.map