backoff-rxjs
Version:
A collection of helpful RxJS operators to deal with backoff strategies (like exponential backoff)
109 lines (93 loc) • 7.63 kB
JavaScript
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("rxjs"));
else if(typeof define === 'function' && define.amd)
define(["rxjs"], factory);
else if(typeof exports === 'object')
exports["backoff-rxjs"] = factory(require("rxjs"));
else
root["backoff-rxjs"] = factory(root["rxjs"]);
})(self, (__WEBPACK_EXTERNAL_MODULE_rxjs__) => {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/index.ts":
/*!**********************!*\
!*** ./src/index.ts ***!
\**********************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.intervalBackoff = exports.retryBackoff = void 0;\nvar retryBackoff_1 = __webpack_require__(/*! ./operators/retryBackoff */ \"./src/operators/retryBackoff.ts\");\nObject.defineProperty(exports, \"retryBackoff\", ({ enumerable: true, get: function () { return retryBackoff_1.retryBackoff; } }));\nvar intervalBackoff_1 = __webpack_require__(/*! ./observable/intervalBackoff */ \"./src/observable/intervalBackoff.ts\");\nObject.defineProperty(exports, \"intervalBackoff\", ({ enumerable: true, get: function () { return intervalBackoff_1.intervalBackoff; } }));\n\n\n//# sourceURL=webpack://backoff-rxjs/./src/index.ts?");
/***/ }),
/***/ "./src/observable/intervalBackoff.ts":
/*!*******************************************!*\
!*** ./src/observable/intervalBackoff.ts ***!
\*******************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.intervalBackoff = void 0;\nvar rxjs_1 = __webpack_require__(/*! rxjs */ \"rxjs\");\nvar utils_1 = __webpack_require__(/*! ../utils */ \"./src/utils.ts\");\nfunction intervalBackoff(config, scheduler) {\n if (scheduler === void 0) { scheduler = rxjs_1.asyncScheduler; }\n var _a = typeof config === 'number' ? { initialInterval: config } : config, initialInterval = _a.initialInterval, _b = _a.maxInterval, maxInterval = _b === void 0 ? Infinity : _b, _c = _a.backoffDelay, backoffDelay = _c === void 0 ? utils_1.exponentialBackoffDelay : _c;\n initialInterval = initialInterval < 0 ? 0 : initialInterval;\n return (0, rxjs_1.of)(0, scheduler).pipe((0, rxjs_1.expand)(function (iteration) {\n return (0, rxjs_1.timer)((0, utils_1.getDelay)(backoffDelay(iteration, initialInterval), maxInterval))\n .pipe((0, rxjs_1.mapTo)(iteration + 1));\n }));\n}\nexports.intervalBackoff = intervalBackoff;\n\n\n//# sourceURL=webpack://backoff-rxjs/./src/observable/intervalBackoff.ts?");
/***/ }),
/***/ "./src/operators/retryBackoff.ts":
/*!***************************************!*\
!*** ./src/operators/retryBackoff.ts ***!
\***************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.retryBackoff = void 0;\nvar rxjs_1 = __webpack_require__(/*! rxjs */ \"rxjs\");\nvar utils_1 = __webpack_require__(/*! ../utils */ \"./src/utils.ts\");\nfunction retryBackoff(config) {\n var _a = typeof config === 'number' ? { initialInterval: config } : config, initialInterval = _a.initialInterval, _b = _a.maxRetries, maxRetries = _b === void 0 ? Infinity : _b, _c = _a.maxInterval, maxInterval = _c === void 0 ? Infinity : _c, _d = _a.shouldRetry, shouldRetry = _d === void 0 ? function () { return true; } : _d, _e = _a.resetOnSuccess, resetOnSuccess = _e === void 0 ? false : _e, _f = _a.backoffDelay, backoffDelay = _f === void 0 ? utils_1.exponentialBackoffDelay : _f;\n return function (source) {\n return (0, rxjs_1.defer)(function () {\n var index = 0;\n return source.pipe((0, rxjs_1.retryWhen)(function (errors) {\n return errors.pipe((0, rxjs_1.concatMap)(function (error) {\n var attempt = index++;\n return (0, rxjs_1.iif)(function () { return attempt < maxRetries && shouldRetry(error); }, (0, rxjs_1.timer)((0, utils_1.getDelay)(backoffDelay(attempt, initialInterval), maxInterval)), (0, rxjs_1.throwError)(error));\n }));\n }), (0, rxjs_1.tap)(function () {\n if (resetOnSuccess) {\n index = 0;\n }\n }));\n });\n };\n}\nexports.retryBackoff = retryBackoff;\n\n\n//# sourceURL=webpack://backoff-rxjs/./src/operators/retryBackoff.ts?");
/***/ }),
/***/ "./src/utils.ts":
/*!**********************!*\
!*** ./src/utils.ts ***!
\**********************/
/***/ ((__unused_webpack_module, exports) => {
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.exponentialBackoffDelay = exports.getDelay = void 0;\nfunction getDelay(backoffDelay, maxInterval) {\n return Math.min(backoffDelay, maxInterval);\n}\nexports.getDelay = getDelay;\nfunction exponentialBackoffDelay(iteration, initialInterval) {\n return Math.pow(2, iteration) * initialInterval;\n}\nexports.exponentialBackoffDelay = exponentialBackoffDelay;\n\n\n//# sourceURL=webpack://backoff-rxjs/./src/utils.ts?");
/***/ }),
/***/ "rxjs":
/*!************************************************************************************!*\
!*** external {"root":["rxjs"],"commonjs":"rxjs","commonjs2":"rxjs","amd":"rxjs"} ***!
\************************************************************************************/
/***/ ((module) => {
module.exports = __WEBPACK_EXTERNAL_MODULE_rxjs__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
/******/
/******/ return __webpack_exports__;
/******/ })()
;
});