Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stifle

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stifle

A very simple way to throttle a function

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4K
decreased by-20.95%
Maintainers
1
Weekly downloads
 
Created
Source

stifle

Wrap a function, so it is only called (at most) once every X milliseconds.

    var stifle = require('stifle')

    // A silly little clock
    function tellTime () {
      console.log('The time is now ' + new Date())
    }

    // Only show the time once per second
    var secondHand = stifle(tellTime, 1000)

    // Call it like crazy, but it will only fire once per second
    var interval = setInterval(secondHand, 10)

Cancellation

The wrapped function comes with a cancel method to kill and pending future invocations -- useful for shutting it down when a page or component is being unloaded.

    // Stop calling the secondHand
    clearInterval(interval)

    // Cancel pending calls, or else it will fire one more time
    secondHand.cancel()

No Extras

To keep it fast and simple, stifle does not support:

  • passing parameters
  • returning values
  • recursive invocation
  • "flushing" pending invocations
  • leading/trailing options

If you want those fancy features, check out lodash.throttle

FAQs

Package last updated on 31 Jan 2018

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