Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

throttleit

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

throttleit

Throttle a function to limit its execution rate

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
14M
11.09%
Maintainers
0
Weekly downloads
 
Created
Source

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.

function

Type: function

The function to be throttled.

wait

Type: number

The number of milliseconds to throttle invocations to.

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

Keywords

throttle

FAQs

Package last updated on 21 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts