GitXplorerGitXplorer
e

retry-promise

public
3 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
42f7e6faad68b9912c58f29a423bc6f40a82ae89

fix: the number of retries is not as expected

eemojiiii committed 2 years ago
Unverified
4cd75c7489b3b8c233f2d0e205e8219a5bb4de44

fix: when executing abort, an error will be reported if the promise has not returned

eemojiiii committed 2 years ago
Unverified
097e5c5b3487dd97bd24fe2900aabc2e0494d5bb

Merge branch 'main' of https://github.com/emojiiii/retry-promise into main

eemojiiii committed 2 years ago
Unverified
de0d1953ff0bc6d927b121fd16a77e94e8c91dc6

fix: invalid fields

eemojiiii committed 2 years ago
Verified
9fb74f5e17285d4d55b2567f45053dc8c4ef2bc8

docs: update readme

eemojiiii committed 2 years ago
Unverified
288fb2d7909a7991b8aed3d65690dd2f35d4d28f

fix: can not resolve promise

eemojiiii committed 2 years ago

README

The README file for this repository.

retry-promise

Retrying failed promises and break promises at any time

Installation

npm instal --save-dev @emojiiii/retry-promise
yarn add @emojiiii/retry-promise
pnpm add @emojiiii/retry-promise

Example

Base Usage

import {retryPromiseFactory} from '@emojiiii/retry-promise'

let counter = 0
let promise = retryPromiseFactory(() => {
      counter += 1;
      if (counter === 3) {
          return Promise.resolve('success');
     } else {
        return Promise.reject('fail')
     }
})

promise().then(() => {
  console.log('Operation succeeded!')
}).catch((err) => {
   console.log('err: ', err)
})

MaxRetries

import {retryPromiseFactory} from '@emojiiii/retry-promise'

let counter = 0
let promise = retryPromiseFactory(() => {
      counter += 1;
      if (counter === 3) {
          return Promise.resolve('success');
     } else {
        return Promise.reject('fail')
     }
}, {
  maxRetries: 5,
  retryDelayType: 'exponential',
  maxRetryDelay: 60000
})

promise().then(() => {
  console.log('Operation succeeded!')
}).catch((err) => {
   console.log('err: ', err)
})

retryDelayType

import {retryPromiseFactory} from '@emojiiii/retry-promise'

let counter = 0
let promise = retryPromiseFactory(() => {
      counter += 1;
      if (counter === 3) {
          return Promise.resolve('success');
     } else {
        return Promise.reject('fail')
     }
}, {
  maxRetries: 5,
  retryDelayType: 'fixed',
  retryDelay: 1000
})

promise().then(() => {
  console.log('Operation succeeded!')
}).catch((err) => {
   console.log('err: ', err)
})

Abort promise

import {retryPromiseFactory} from '@emojiiii/retry-promise'

let counter = 0
let promise = retryPromiseFactory(() => {
      counter += 1;
      if (counter === 3) {
          return Promise.resolve('success');
     } else {
        return Promise.reject('fail')
     }
})

promise().then(() => {
  console.log('Operation succeeded!')
}).catch((err) => {
   console.log('err: ', err)
})

promise.abort('abort')

License

retry-promise is open source software licensed as MIT