Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/throttleit
Throttle a function to limit its execution rate
https://github.com/sindresorhus/throttleit
Last synced: 1 day ago
JSON representation
Throttle a function to limit its execution rate
- Host: GitHub
- URL: https://github.com/sindresorhus/throttleit
- Owner: sindresorhus
- License: mit
- Created: 2013-03-26T21:12:30.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2024-06-21T22:51:00.000Z (6 months ago)
- Last Synced: 2024-12-08T12:19:57.765Z (6 days ago)
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 95
- Watchers: 7
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
- Security: .github/security.md
Awesome Lists containing this project
README
# throttleit
> Throttle a function to limit its execution rate
## Install
```sh
npm install throttleit
```## Usage
```js
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.
#### function
Type: `function`
The function to be throttled.
#### wait
Type: `number`
The number of milliseconds to throttle invocations to.
## Related
- [p-throttle](https://github.com/sindresorhus/p-throttle) - Throttle async functions
- [debounce](https://github.com/sindresorhus/debounce) - Delay function calls until a set time elapses after the last invocation