Socket
Socket
Sign inDemoInstall

http-client-request-retry

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    http-client-request-retry

http client request retry、请求重试


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Install size
3.20 kB
Created
Weekly downloads
 

Readme

Source

安装

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)
})

Keywords

FAQs

Last updated on 23 Jul 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc