Giter Club home page Giter Club logo

wx-queue-request's Introduction

wx-queue-request

管理微信小程序 wx.request 方法的并发数,解决请求数大于 10 时,直接不请求的问题。如果需要 wx.request 方法支持 Promise,可以使用 wx-promise-request 库哦。

下载

由于小程序不支持 npm,所以直接右键保存 index.js 文件即可。

使用

在 app.js 引入并执行即可

import { queue } from './wx-queue-request'
queue()

// 因为请求队列被管理
// 即使并发请求数超过 10 也不会报错了
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})
wx.request({url: 'test.php'})

API

queue([concurrency])

直接对全局的 wx.request 进行封装,调用后 wx.request 即会管理队列。并发数默认为 10。

import { queue } from './wx-queue-request'
queue(5) // 指定并发数为 5

wx.request({url: 'test.php'})

queueRequest(request, [concurrency])

对指定请求函数进行封装,返回被管理队列的函数,并发数 concurrency 默认为 10。

import { queueRequest } from './wx-queue-request'

export default queueRequest(wx.request, 10)

License

MIT

wx-queue-request's People

Contributors

zhengjunxin avatar

Watchers

lemonhall avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.