0.0.2 • Published 4 years ago

http-client-request-retry v0.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

安装

npm install httpClientRequestRetry

用法

语法

httpClientRequestRetry(promise, totalCount, millisecond)

参数

参数描述
promisePromise实例
totalCount请求次数
millisecond请求时间间隔,单位是ms

返回

TYPE描述
Promise返回一个Promise实例

例子

import httpClientRequestRetry from 'httpClientRequestRetry'

/**
 * @function 模拟请求函数
 * @returns {Promise<any>}
 */
function query() {
  return new Promise((resolve, reject) => {
    let random = Math.floor(Math.random() * 10)
    console.log(1)
    setTimeout(() => {
      if (random > 5) {
        resolve({code: 0, msg: '成功'})
      } else {
        reject({code: 1, msg: '失败'})
      }
    }, 1000)
  })
}

/**
 * @function 发起一个请求,最多请求五次,如果五次还不成功,就结束
 */
httpClientRequestRetry(query(), 5, 1000)
  .then((res) => {
    console.log(res)
  }).catch((err) => {
  console.log(err)
})
0.0.2

4 years ago

0.0.1

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago