
Product
Introducing Module Reachability: Focus on the Vulnerabilities That Matter
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
superagent-throttle
Advanced tools
A plugin for superagent that throttles requests. Useful for rate or concurrency limited APIs.
.use(throttle.plugin())
architecture npm i --save superagent-throttle
const request = require('superagent')
const Throttle = require('superagent-throttle')
let throttle = new Throttle({
active: true, // set false to pause queue
rate: 5, // how many requests can be sent every `ratePer`
ratePer: 10000, // number of ms in which `rate` requests may be sent
concurrent: 2 // how many requests can be sent concurrently
})
request
.get('http://placekitten.com/100/100')
.use(throttle.plugin())
.end((err, res) => { ... })
const request = require('superagent')
const Throttle = require('superagent-throttle')
let throttle = new Throttle()
.on('sent', (request) => { ... }) // sent a request
.on('received', (request) => { ... }) // received a response
.on('drained', () => { ... }) // received last response
// node 6
import Throttle from 'superagent-throttle'
// node 4
var Throttle = require('superagent-throttle/dist/node4')
// all browsers supported by superagent
var Throttle = require('superagent-throttle/dist/browser')
When using API's to update a client, you may want some serialised requests which
still count towards your rate limit, but do not block other requests. You can
do that by passing a uri (not necessarily a valid url) to throttle.plugin
, for
those requests you want to serialise, and leave it out for other async requests.
This can be done on the fly, you don't need to initialise subqueues first.
let endpoint = 'http://example.com/endpoint'
request
.get(endpoint)
.set('someData': someData)
.use(throttle.plugin(endpoint))
.end(callback)
it's common to use an endpoint for the uri, simply to serialise requests to that endpoint without interfering with requests to other endpoints
active
: whether or not the queue is paused. (default: true)rate
: how many requests can be sent every ratePer
. (default: 40)ratePer
: number of ms in which rate
requests may be sent. (default: 40000)concurrent
: how many requests can be sent concurrently. (default: 20)Options can be set after instantiation using the options
method.
var throttle = new require('./index')({ active: false }) // start paused
throttle.options('active', true) // unpause
- **npm run jsdoc** : `rm -fr ./docs/* && jsdoc lib -d docs`
npm run jsdoc && npm run gh-pages
node-readme
gh-pages -d docs
npm run babel:node4 && npm run babel:browser && npm run babel:node6 && npm run readme && npm run docs
cross-env NODE_ENV=node4 babel lib -d dist/node4
cross-env NODE_ENV=browser babel lib -d dist/browser
cross-env NODE_ENV=node6 babel lib -d dist
cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text --check-coverage --lines 100 npm run test
cross-env NODE_ENV=test mocha --compilers js:babel-register test
cross-env NODE_ENV=test mocha --compilers js:babel-register --watch test
npm run build
git push && git push --tags
See the fancy annotated code.
Levi Wheatcroft levi@wht.cr
Contributions welcome; Please submit all pull requests against the master branch.
FAQs
A plugin for superagent that throttles requests.
The npm package superagent-throttle receives a total of 4,851 weekly downloads. As such, superagent-throttle popularity was classified as popular.
We found that superagent-throttle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.
Research
Security News
Socket researchers uncovered malicious npm and PyPI packages that steal crypto wallet credentials using Google Analytics and Telegram for exfiltration.