1.2.0 • Published 5 years ago

async-retry.ts v1.2.0

Weekly downloads
4,078
License
ISC
Repository
github
Last release
5 years ago

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
1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago