@pefish/js-decorator
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

js Decorators

retry decorator

/**
 * 函数重试。函数返回字符串 retry 则重试。只能修饰异步函数
 * @param times 重试次数
 * @param errContainStr 当错误信息中包含这个字符串,则重试
 * @param interval 重试间隔时间
 */
class Test {
  a: number = 0

  @retry(6, `haha`)
  async test (a: string): Promise<string> {
    this.a++
    // throw new Error(`4351`)
    if (this.a !== 5) {
      throw new Error(`haha`) // trigger retry
    }
    return `1212`
  }
}

const t = new Test()
t.test(`11`).then((d) => {
  console.log(d)
}).catch((err) => {
  console.error(`err: `, err)
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.6
    1
    • latest

Version History

Package Sidebar

Install

npm i @pefish/js-decorator

Weekly Downloads

1

Version

0.0.6

License

MIT

Unpacked Size

11.1 kB

Total Files

10

Last publish

Collaborators

  • pefish