@f/throttle

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @f/throttle

Weekly Downloads

5

Version

1.0.0

License

MIT

Last publish

Collaborators

  • f