async-retry.ts
async await version of co-retry.js, which can be used in both TypeScript and JavaScript.
![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)
![LICENSE](https://img.shields.io/badge/license-Anti%20996-blue.svg)
[
](https://sonarcloud.io
/dashboard?id=Jeff-Tian_async-retry.ts)
安装
npm install async-retry.ts --save
用法
简单示例:
TypeScript:
非 async 版:
import Action from 'async-retry.ts'
const action = () => {}
const handlers = [
{
error: 'error1',
handler: yourHandler1,
},
{
error: 'error2',
handler: yourHandler2,
},
]
Action.retry(action, 3, handlers)
async 版:
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)
JavaScript:
非 async 版:
const Action = require('async-retry.ts').default
const action = () => {}
const handlers = [
{
error: 'error1',
handler: yourHandler1,
},
{
error: 'error2',
handler: yourHandler2,
},
]
Action.retry(action, 3, handlers)
async 版
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)
完整示例:
开发
-
修改代码后跑
npm test
确保测试通过。
-
git commit
-
npm version patch/minor/major
-
npm publish