Odoo GraphQL Subscription using Node, Express JS for Sample
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
9.6 KiB

4 months ago
{"version":3,"file":"retry.cjs","sources":["delayFunction.js","retryFunction.js","retryLink.js"],"sourcesContent":["export function buildDelayFunction(delayOptions) {\n var _a = delayOptions || {}, _b = _a.initial, initial = _b === void 0 ? 300 : _b, _c = _a.jitter, jitter = _c === void 0 ? true : _c, _d = _a.max, max = _d === void 0 ? Infinity : _d;\n // If we're jittering, baseDelay is half of the maximum delay for that\n // attempt (and is, on average, the delay we will encounter).\n // If we're not jittering, adjust baseDelay so that the first attempt\n // lines up with initialDelay, for everyone's sanity.\n var baseDelay = jitter ? initial : initial / 2;\n return function delayFunction(count) {\n var delay = Math.min(max, baseDelay * Math.pow(2, count));\n if (jitter) {\n // We opt for a full jitter approach for a mostly uniform distribution,\n // but bound it within initialDelay and delay for everyone's sanity.\n delay = Math.random() * delay;\n }\n return delay;\n };\n}\n//# sourceMappingURL=delayFunction.js.map","export function buildRetryFunction(retryOptions) {\n var _a = retryOptions || {}, retryIf = _a.retryIf, _b = _a.max, max = _b === void 0 ? 5 : _b;\n return function retryFunction(count, operation, error) {\n if (count >= max)\n return false;\n return retryIf ? retryIf(error, operation) : !!error;\n };\n}\n//# sourceMappingURL=retryFunction.js.map","import { __awaiter, __extends, __generator } from \"tslib\";\nimport { ApolloLink } from \"../core/index.js\";\nimport { Observable } from \"../../utilities/index.js\";\nimport { buildDelayFunction } from \"./delayFunction.js\";\nimport { buildRetryFunction } from \"./retryFunction.js\";\n/**\n * Tracking and management of operations that may be (or currently are) retried.\n */\nvar RetryableOperation = /** @class */ (function () {\n function RetryableOperation(observer, operation, forward, delayFor, retryIf) {\n var _this = this;\n this.observer = observer;\n this.operation = operation;\n this.forward = forward;\n this.delayFor = delayFor;\n this.retryIf = retryIf;\n this.retryCount = 0;\n this.currentSubscription = null;\n this.onError = function (error) { return __awaiter(_this, void 0, void 0, function () {\n var shouldRetry;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n this.retryCount += 1;\n return [4 /*yield*/, this.retryIf(this.retryCount, this.operation, error)];\n case 1:\n shouldRetry = _a.sent();\n if (shouldRetry) {\n this.scheduleRetry(this.delayFor(this.retryCount, this.operation, error));\n return [2 /*return*/];\n }\n this.observer.error(error);\n return [2 /*return*/];\n }\n });\n }); };\n this.try();\n }\n /**\n * Stop retrying for the operation, and cancel any in-progress requests.\n */\n RetryableOperation.prototype.cancel = function () {\n if (this.currentSubscription) {\n this.currentSubscription.unsubscribe();\n }\n clearTimeout(this.timerId);\n this.timerId = undefined;\n this.currentSubscription = null;\n };\n RetryableOperation.prototype.try = function () {\n this.currentSubscription = this.forward(this.operation).subscribe({\n next: this.observer.next.bind(this.observer),\n error: this.onError,\n complete: this.observer.complete.bind(this.observer),\n });\n };\n RetryableOperation.prototype.scheduleRetry = function (delay) {\n var _this = this;\n if (this.timerId) {\n throw new Error(\"RetryLink BUG! Encountered overlapping retries\");\n }\n