Retrying failed promises and break promises at any time
npm instal --save-dev @emojiiii/retry-promise
yarn add @emojiiii/retry-promise
pnpm add @emojiiii/retry-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)
})
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)
})
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)
})
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')
retry-promise is open source software licensed as MIT