async await version of co-retry.js, which can be used in both TypeScript and JavaScript.
[](https://sonarcloud.io /dashboard?id=Jeff-Tian_async-retry.ts)
npm install async-retry.ts --save
# or
yarn add async-retry.ts
import Action from 'async-retry.ts'
const action = () => {}
const handlers = [
{
error: 'error1',
handler: yourHandler1,
},
{
error: 'error2',
handler: yourHandler2,
},
]
Action.retry(action, 3, handlers)
import Action from 'async-retry.ts'
const action = async()=>{}
const handlers = [{
error: 'error1',
handler: async yourHandler1()=>{}
}, {
error: 'error2',
handler: async yourHandler2()=>{}
}]
await Action.retryAsync(action, 3, handlers)
const Action = require('async-retry.ts').default
const action = () => {}
const handlers = [
{
error: 'error1',
handler: yourHandler1,
},
{
error: 'error2',
handler: yourHandler2,
},
]
Action.retry(action, 3, handlers)
const Action =require('async-retry.ts').default
const action = async()=>{}
const handlers = [{
error: 'error1',
handler: async yourHandler1()=>{}
}, {
error: 'error2',
handler: async yourHandler2()=>{}
}]
await Action.retryAsync(action, 3, handlers)
Add delay logic in your error handlers, like so
import Action from 'async-retry.ts'
const action = async()=>{}
const handlers = [{
error: 'error1',
handler: async yourHandler1()=>{
await new Promise(resolve => setTimeout(resolve, 1000))
// handling
}
}, {
error: 'error2',
handler: async yourHandler2()=>{
await new Promise(resolve => setTimeout(resolve, 1000))
// handling...
}
}]
await Action.retryAsync(action, 3, handlers)
-
Run after code change
npm test # or yarn test
Make sure all tests pass。
-
git commit
-
npm version patch/minor/major
-
npm publish