rate-ping-pong

1.0.1 • Public • Published

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 () {
  // HIGH USAGE METHOD
}, {
  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

limiter.run('a') // Called in 100ms returns Promise.resolve('a')
limiter.run('b') // Called in 200ms returns Promise.resolve('b')
limiter.run('c') // Called in 300ms returns Promise.resolve('c')
  1. setTimer(Number) -> undefined

Changes the rate limiting logic to execute once every 1000 milliseconds

limiter.setTimer(1000)
  1. incrementTimer(Number) -> undefined

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

limiter.incrementTimer()
  1. decrementTimer(Number) -> undefined

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

limiter.decrementTimer()
  1. resetTimer() -> undefined

Reset the timer to the originally supplied value

limiter.resetTimer()

Package Sidebar

Install

npm i rate-ping-pong

Weekly Downloads

1

Version

1.0.1

License

ISC

Last publish

Collaborators

  • rphansen91