@f/throttle

Throttle function

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
30Oct 27, 2016Oct 27, 2016Minified + gzip package size for @f/throttle in KB

Readme

throttle

Build status Git tag NPM version Code style

Throttle function

Installation

$ npm install @f/throttle

Usage

Throttling a function causes that function to only execute, at most, once every ms milliseconds. Each time it's called, one of two things happens:

  • If there is no pending run, one is queued to run in ms milliseconds.
  • If one is pending, nothing happens. It just continues to wait for the pending one to run.

Example

var throttle = require('@f/throttle')

// Runs at most every 100 milliseconds, regardless of how many scroll events happen
window.addEventListener('scroll', throttle(updateScrollSpy, 100))

API

throttle(fn, ms)

  • fn - The function to throttle
  • ms - The time in milliseconds to throttle it for.

Returns: A throttled version of fn. When called, this function returns a cancel function that can be used to stop a pending execution.

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.