throttleit
Throttle a function to limit its execution rate
Last updated 5 months ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install throttleit 
SYNC missed versions from official npm registry.

throttleit

Throttle a function to limit its execution rate

Install

npm install throttleit

Usage

import throttle from 'throttleit';

// Throttling a function that processes data.
function processData(data) {
	console.log('Processing:', data);

	// Add data processing logic here.
}

// Throttle the `processData` function to be called at most once every 3 seconds.
const throttledProcessData = throttle(processData, 3000);

// Simulate calling the function multiple times with different data.
throttledProcessData('Data 1');
throttledProcessData('Data 2');
throttledProcessData('Data 3');

API

throttle(function, wait)

Creates a throttled function that limits calls to the original function to at most once every wait milliseconds. It guarantees execution after the final invocation and maintains the last context (this) and arguments.

The throttled function returns the result of the most recent execution of the original function. When a call is deferred, it returns the result from the previous execution (or undefined if it has not executed yet).

function

Type: Function

The function to be throttled.

wait

Type: number

The number of milliseconds to throttle invocations to.

Must be a non-negative finite number.

Related

  • p-throttle - Throttle async functions
  • debounce - Delay function calls until a set time elapses after the last invocation

Current Tags

  • 3.0.0                                ...           latest (5 months ago)

7 Versions

  • 3.0.0                                ...           5 months ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           12 years ago
  • 0.0.2                                ...           14 years ago
  • 0.0.1                                ...           14 years ago
Maintainers (1)
Downloads
Total 29
Today 0
This Week 3
This Month 17
Last Day 0
Last Week 4
Last Month 7
Dependencies (0)
None
Dev Dependencies (1)
  • xo ^4.0.0

© 2010 - cnpmjs.org x YWFE | Home | YWFE