npm.io
0.7.0 • Published 5 years ago

@huudan/retry-promise-util

Licence
MIT
Version
0.7.0
Deps
0
Size
9 kB
Vulns
0
Weekly
0

@huudan/retry-promise-util

Retries a function returning a promise with a delay between each retry

Usage

import { retryPromise } from '@huudan/retry-promise-util';

retryPromise(() => fetch('https://api.example.com'), {
  delay: 2000, // Milliseconds between each retry
  multiplier: 2, // Multiplier for delay (ex: 2000, 4000, 8000...)
  retries: 3 // Number of retries after the promise is rejected
}).then((response) => response.json())
  .then(console.log)
  .catch(console.error);

Keywords