Socket
Socket
Sign inDemoInstall

backoff-rxjs

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backoff-rxjs - npm Package Compare versions

Comparing version 6.1.2 to 6.2.2

8

dist/index.js

@@ -1,6 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var retryBackoff_1 = require("./operators/retryBackoff");
exports.retryBackoff = retryBackoff_1.retryBackoff;
var intervalBackoff_1 = require("./observable/intervalBackoff");
exports.intervalBackoff = intervalBackoff_1.intervalBackoff;
export { retryBackoff } from './operators/retryBackoff';
export { intervalBackoff } from './observable/intervalBackoff';

@@ -1,6 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var utils_1 = require("../utils");
import { of, timer, asyncScheduler } from 'rxjs';
import { expand, mapTo } from 'rxjs/operators';
import { exponentialBackoffDelay, getDelay } from '../utils';
/**

@@ -10,15 +8,14 @@ * Creates an Observable that emits sequential numbers with by default

*/
function intervalBackoff(config, scheduler) {
if (scheduler === void 0) { scheduler = rxjs_1.asyncScheduler; }
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;
export function intervalBackoff(config, scheduler) {
if (scheduler === void 0) { scheduler = asyncScheduler; }
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 ? exponentialBackoffDelay : _c;
initialInterval = (initialInterval < 0) ? 0 : initialInterval;
return rxjs_1.of(0, scheduler).pipe(
return of(0, scheduler).pipe(
// Expend starts with number 1 and then recursively
// projects each value to new Observable and puts it back in.
operators_1.expand(function (iteration) {
return rxjs_1.timer(utils_1.getDelay(backoffDelay(iteration, initialInterval), maxInterval))
expand(function (iteration) {
return timer(getDelay(backoffDelay(iteration, initialInterval), maxInterval))
// Once timer is complete, iteration is increased
.pipe(operators_1.mapTo(iteration + 1));
.pipe(mapTo(iteration + 1));
}));
}
exports.intervalBackoff = intervalBackoff;

@@ -1,6 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var utils_1 = require("../utils");
import { iif, throwError, timer } from 'rxjs';
import { concatMap, retryWhen } from 'rxjs/operators';
import { getDelay, exponentialBackoffDelay } from '../utils';
/**

@@ -14,8 +12,8 @@ * Returns an Observable that mirrors the source Observable with the exception

*/
function retryBackoff(config) {
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.backoffDelay, backoffDelay = _e === void 0 ? utils_1.exponentialBackoffDelay : _e;
export function retryBackoff(config) {
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.backoffDelay, backoffDelay = _e === void 0 ? exponentialBackoffDelay : _e;
return function (source) {
return source.pipe(operators_1.retryWhen(function (errors) {
return errors.pipe(operators_1.concatMap(function (error, i) {
return rxjs_1.iif(function () { return i < maxRetries && shouldRetry(error); }, rxjs_1.timer(utils_1.getDelay(backoffDelay(i, initialInterval), maxInterval)), rxjs_1.throwError(error));
return source.pipe(retryWhen(function (errors) {
return errors.pipe(concatMap(function (error, i) {
return iif(function () { return i < maxRetries && shouldRetry(error); }, timer(getDelay(backoffDelay(i, initialInterval), maxInterval)), throwError(error));
}));

@@ -25,2 +23,1 @@ }));

}
exports.retryBackoff = retryBackoff;

@@ -1,12 +0,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/** Calculates the actual delay which can be limited by maxInterval */
function getDelay(backoffDelay, maxInterval) {
export function getDelay(backoffDelay, maxInterval) {
return Math.min(backoffDelay, maxInterval);
}
exports.getDelay = getDelay;
/** Exponential backoff delay */
function exponentialBackoffDelay(iteration, initialInterval) {
export function exponentialBackoffDelay(iteration, initialInterval) {
return Math.pow(2, iteration) * initialInterval;
}
exports.exponentialBackoffDelay = exponentialBackoffDelay;
{
"name": "backoff-rxjs",
"version": "6.1.2",
"version": "6.2.2",
"description": "A collection of helpful RxJS operators to deal with backoff strategies (like exponential backoff)",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -9,3 +9,3 @@ {

"outDir": "./dist",
"module": "commonjs",
"module": "es2015",
"declaration": true,

@@ -29,7 +29,3 @@ "lib": [

},
"exclude": [
"node_modules",
"dist",
"spec"
]
}
"exclude": ["node_modules", "dist", "spec"]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc