async-retry.ts

async await version of co-retry.js(https://www.npmjs.com/package/co-retry.js), which can be used in both TypeScript and JavaScript.

Usage no npm install needed!

<script type="module">
  import asyncRetryTs from 'https://cdn.skypack.dev/async-retry.ts';
</script>

README

async-retry.ts

async await version of co-retry.js, which can be used in both TypeScript and JavaScript.

npm download NPM version Build Status Dependencies Status Coverage Status code style: prettier

996.icu LICENSE

[Quality gate](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)

完整示例:

开发

  1. 修改代码后跑

    npm test
    

    确保测试通过。

  2. git commit

  3. npm version patch/minor/major

  4. npm publish