promise-cache-retry
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

promise-cache-retry

NPM Version license GitHub Actions Known Vulnerabilities TypeScript Style Guide standard-readme compliant

Table of Contents

Security

Background

If you simply cache the Promise it will always resolve with an error after an error occurs. On the other hand, retrying within a Promise will leave the Promise unresolved until the error is resolved, blocking further processing.

So this library works like this: If an error occurs, resolve it as an error, automatically perform retry processing (unless you disable it explicitly), and return the retry result when referencing the cache.

Install

npm install --save promise-cache-retry

Usage

import { PromiseCache } from 'promise-cache-retry';

const cache = new PromiseCache({
  promiseGenerator: async () => {
    const res = await fetchData(ENDPOINT);
    return res.data;
  },
  options: {
    maxRetries: 2,
    minRetryInterval: 3000,
  },
});

export const handler = async () => {
  const value = await cache.get();
}

Contributing

See the contributing file!

PRs accepted.

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © RICOH360

Readme

Keywords

Package Sidebar

Install

npm i promise-cache-retry

Weekly Downloads

6

Version

0.1.4

License

MIT

Unpacked Size

10.1 kB

Total Files

9

Last publish

Collaborators

  • r360-bot