super-throttle
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Super Throttle

Demo and documentation at: https://t-hugs.github.io/super-throttle/demo

Usage

This package exports a single function: throttle.

Install super-throttle

npm install --save super-throttle

or

yarn add super-throttle

Throttle a function!

let i = 1;
function originalFunction() {
	console.log(i++);
}
const throttledFunction = throttle(originalFunction, { cooldownMs: 500 });
throttledFunction(); // calls originalFunction immediately, starts the cooldown period
throttledFunction(); // cooldown in progress... queue a call for when it is complete
throttledFunction(); // call is already queued! Ignore.
throttledFunction(); // call is already queued! Ignore.
throttledFunction.clearCooldown(); // Force the cooldown to end, causing the queued call to execute.
throttledFunction(); // cooldown in progress... queue a call for when it is complete

Output:

1
2
<500ms passes>
3

Settings

Find the documentation for all settings at https://t-hugs.github.io/super-throttle/demo.

Source

Super Throttle source code is at https://github.com/T-Hugs/super-throttle.

Readme

Keywords

none

Package Sidebar

Install

npm i super-throttle

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

24.2 kB

Total Files

6

Last publish

Collaborators

  • trevorsg