rxjs-retry-delay
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

RxJS-retry-delay operator for rxjs@^6.0.0

RxJS retry pipeable operator that supports delay and max attempts strategy

Prerequisites

rxjs: ^6.0.0

Installation and Usage

npm install rxjs-retry-delay

Basic usage with default values:

import { ajax } from 'rxjs/ajax';
import { retryWithDelay } from 'rxjs-retry-delay';
 
function getUserById(id) {
  return ajax.getJSON(`https://jsonplaceholder.typicode.com/users/${id}`)
    .pipe(retryWithDelay());
}

Example above will retry 3 times with interval of 1s

function getUserById(id) {
  return ajax.getJSON(`https://jsonplaceholder.typicode.com/users/${id}`).pipe(
    retryWithDelay({
      delay: 1000,
      maxRetryAttempts: 5,
      scalingFactor: 2
    })
  );
}

Example above will retry after 1s, 2s, 4s, 8s, 16s

In excludedStatusCodes we can pass response statuses after which we don't want to retry

function getUserById(id) {
  return ajax.getJSON(`https://jsonplaceholder.typicode.com/users/${id}`).pipe(
    retryWithDelay({
      delay: 1000,
      maxRetryAttempts: 10,
      scalingFactor: 2,
      excludedStatusCodes: [500]
    })
  );
}

In example above, when response status is 500 it will throw error immediately.

Running the tests

npm test

or

npm run test:watch

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i rxjs-retry-delay

    Weekly Downloads

    277

    Version

    0.3.1

    License

    MIT

    Unpacked Size

    9.3 kB

    Total Files

    13

    Last publish

    Collaborators

    • filipows