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

dthrottle

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dthrottle

distribution throttle

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-28.57%
Maintainers
1
Weekly downloads
 
Created
Source

dthrottle

Build Status Coverage Status

How it works

Rate limit the invocation of a function by ignore following invocations.

Example

const redis = require('redis')
const dthrottle = require('dthrottle')

function tested () {
  console.log(new Date().toISOString(), 'executing ...')
}

let test = dthrottle(tested, {
  wait: 1000,
  adapter: new dthrottle.Adapters.Redis({
    throttle: 2,
    redis: redis.createClient(),
    prefix: 'dthrottle:example'
  })
})

// even `test` invoked every 100ms, `tested` invoked every 1000ms
setInterval(() => {
  test()
}, 100)

Doc

dthrottle(func, opts)

  • func, the function to be ratelimited
  • opts.wait, invoke the func after opts.wait ms
  • opts.adapter, adapter to be used
  • opts.getId, the function to generate identify id to seprate invocations of func
  • opts.error, callback that will invoked when opts.adapter failed

Adapters

new dthrottle.Adapters.Memory(opts)
  • opts.expire, expire seconds for any locked identify id
new dthrottle.Adapters.Redis(opts)
  • opts.expire, expire seconds for any locked identify id
  • opts.redis, a redis client with Promise APIs
  • opts.prefix, add prefix for keys to be used in dthrottle

Add another Adapter

An adapter should have at least two methods: setnx and clear, both return a Promise.

keep the adapter.setnx atomic

On any invocation, An adapter should lock the identify id to ignore later invocations.

FAQs

Package last updated on 18 Feb 2019

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