UNPKG

envio

Version:

A latency and sync speed optimized, developer friendly blockchain data indexer.

39 lines (34 loc) 1.79 kB
// Generated by ReScript, PLEASE EDIT WITH CARE import * as Utils from "./Utils.res.mjs"; import * as Logging from "./Logging.res.mjs"; import * as ErrorHandling from "./ErrorHandling.res.mjs"; import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; let resolvePromiseAfterDelay = Utils.delay; async function retryAsyncWithExponentialBackOff(backOffMillisOpt, multiplicativeOpt, retryCountOpt, maxRetriesOpt, logger, f) { let backOffMillis = backOffMillisOpt !== undefined ? backOffMillisOpt : 100; let multiplicative = multiplicativeOpt !== undefined ? multiplicativeOpt : 4; let retryCount = retryCountOpt !== undefined ? retryCountOpt : 0; let maxRetries = maxRetriesOpt !== undefined ? maxRetriesOpt : 5; try { return await f(); } catch (raw_exn) { let exn = Primitive_exceptions.internalToException(raw_exn); if (retryCount < maxRetries) { let nextRetryCount = retryCount + 1 | 0; let log = retryCount === 0 ? Logging.childTrace : Logging.childWarn; log(logger, { msg: `Retrying query ` + nextRetryCount.toString() + `/` + maxRetries.toString() + ` in ` + backOffMillis.toString() + `ms - waiting for correct result.`, err: Utils.prettifyExn(exn) }); await Utils.delay(backOffMillis); return await retryAsyncWithExponentialBackOff(backOffMillis * multiplicative | 0, multiplicative, nextRetryCount, maxRetries, logger, f); } ErrorHandling.log(ErrorHandling.make(exn, logger, `Failure. Max retries ` + retryCount.toString() + `/` + maxRetries.toString() + ` exceeded`)); return await Promise.reject(Primitive_exceptions.internalToException(exn)); } } export { resolvePromiseAfterDelay, retryAsyncWithExponentialBackOff, } /* Utils Not a pure module */