
Security News
Python Adopts Standard Lock File Format for Reproducible Installs
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
The p-debounce npm package is a utility for debouncing promise-returning and async functions. Debouncing is a technique used to limit the rate at which a function can fire. It ensures that the function is only called once after a specified delay has elapsed since the last time it was invoked.
Basic Debouncing
This feature allows you to debounce an async function. The function will only be called once after the specified delay (200ms in this case) has elapsed since the last invocation.
const pDebounce = require('p-debounce');
const expensiveFunction = async input => {
console.log('Processing:', input);
return input;
};
const debouncedFunction = pDebounce(expensiveFunction, 200);
debouncedFunction('first call');
debouncedFunction('second call');
// Only 'second call' will be processed after 200ms
Debouncing with Leading Edge
This feature allows you to debounce an async function with the option to trigger the function on the leading edge of the delay period. This means the function will be called immediately on the first invocation and then debounced for subsequent calls.
const pDebounce = require('p-debounce');
const expensiveFunction = async input => {
console.log('Processing:', input);
return input;
};
const debouncedFunction = pDebounce(expensiveFunction, 200, {leading: true});
debouncedFunction('first call');
debouncedFunction('second call');
// 'first call' will be processed immediately, 'second call' will be ignored if it occurs within 200ms
lodash.debounce is a popular utility from the Lodash library that provides similar debouncing functionality. It is widely used and well-documented, but it does not natively support promise-returning or async functions like p-debounce does.
debounce is a lightweight npm package that provides basic debouncing functionality. It is simple and easy to use but lacks the advanced features and async support that p-debounce offers.
throttle-debounce is a package that provides both throttling and debouncing utilities. It is versatile and can be used for various rate-limiting scenarios, but it does not specifically cater to promise-returning or async functions like p-debounce.
Debounce promise-returning & async functions
$ npm install p-debounce
const pDebounce = require('p-debounce');
const expensiveCall = async input => input;
const debouncedFn = pDebounce(expensiveCall, 200);
for (const i of [1, 2, 3]) {
debouncedFn(i).then(console.log);
}
//=> 3
//=> 3
//=> 3
Returns a function that delays calling fn
until after wait
milliseconds have elapsed since the last time it was called.
Type: Function
Promise-returning/async function to debounce.
Type: number
Milliseconds to wait before calling fn
.
Type: Object
Type: boolean
Default: false
Call the fn
on the leading edge of the timeout. Meaning immediately, instead of waiting for wait
milliseconds.
MIT © Sindre Sorhus
FAQs
Debounce promise-returning & async functions
The npm package p-debounce receives a total of 148,353 weekly downloads. As such, p-debounce popularity was classified as popular.
We found that p-debounce demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.