New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

p-debounce

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-debounce

Debounce promise-returning & async functions

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is p-debounce?

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.

What are p-debounce's main functionalities?

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

Other packages similar to p-debounce

Keywords

FAQs

Package last updated on 20 Apr 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc