New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

limiter-component

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

limiter-component

Limits the rate of function calls to one per period. It delays but does not throttle the calls.

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

NPM version Build Status Dependency Status

limiter

Limits the rate of function calls to one per period. It delays but does not throttle the calls. Useful when your codes needs to behave well when calling rate limited API.

If you need something more flexible use rate limiter

Installation

$ npm install --save limiter-component

Usage

Create limiter with desired interval setting. Call trigger passing a function that you want to limit.

var limiter = require('limiter'),
	l = limiter(500); // interval in millis

function doThis() {
  // this is called at most twice per second
}

function doThat() {
  // you can rate limit different functions
}


l.trigger(doThis);
l.trigger(doThat);
l.trigger(doThis);
l.trigger(function() {
	l.penalty(); // wait a bit longer next time
});
l.trigger(doThat);

API

limiter(interval, [penaltyInterval])

Create limiter with desired interval (in millis). Optional penaltyInterval is used instead of interval if limiter.penalty() has been called at least once since last limited function has been triggered.

trigger(fn)

Add fn to limiter queue. It will be called when interval elapsed since another function from the queue was called.

penalty()

Make limiter to use penaltyInterval before triggering next function.

cancel()

Empty limiter queue. Remove all pending trigger request. No methods from the queue is called after cancel.

License

MIT

Keywords

FAQs

Package last updated on 15 Jan 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc