Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including rate-ping-pong with all npm packages installed. Try it out:

var ratePingPong = require("rate-ping-pong")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

rate-ping-pong v1.0.1

Rate limit methods and adjust behavior according to current usage rates

Rate Ping

Maintain zippy user experience while constantly adjusting to various API usage restrictions.

  • Install

npm install rate-ping-pong

  • Setup
const RatePingPong = require('rate-ping-pong')
const limiter = new RatePingPong(function highUsage () {
}, {
  timer: 0,
  minimum: 0,
  maximum: null,
  increment: 100
  • Usage
  1. run(args) -> Promise

Call the highUsage method with supplied arguments, only allow 1 function execution per timer interval Returns a Promise which resolves after function execution'a') // Called in 100ms returns Promise.resolve('a')'b') // Called in 200ms returns Promise.resolve('b')'c') // Called in 300ms returns Promise.resolve('c')
  1. setTimer(Number) -> undefined

Changes the rate limiting logic to execute once every 1000 milliseconds

  1. incrementTimer(Number) -> undefined

Increment the timer by the inc option, do not increase greater than max if supplied

  1. decrementTimer(Number) -> undefined

Decrement the timer by the inc option, do not decrease below the min

  1. resetTimer() -> undefined

Reset the timer to the originally supplied value



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free