JSPM

croq-throttler

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q15671F
  • License GNUv3

Throttler and rate limiter client side, use Promise

Package Exports

  • croq-throttler

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (croq-throttler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Throttler

Throttler to limit parallel request and rate

Constructor

Throttler(nb, rate, send)
  • nb is the number of parallel request
  • rate is an object which defined the time windows rate limiting, it contain nb and time in ms
  • send is a function which send back a promise, it's what we try to throttle

Use

just call throttler.send() and it will return a promise which will be resolve when the request has been sent

Demo

the important file is Throttler.js the rest is here for Demo purpose, you can launch the Demo with

npm run installDemo
npm run demo

and connect with your browser on port 9001, after clicking a bit on the send button you should see:

interface

Polling

in my example client.js I use a polling mechanism, so the request given to the throttler don't need to be a simple request. In the demo, the first request is to start the computation, then poll the result every second