Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/debounce-promise

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/debounce-promise

TypeScript definitions for debounce-promise

  • 3.1.9
  • ts4.5
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @types/debounce-promise?

@types/debounce-promise provides TypeScript type definitions for the debounce-promise package, which is used to debounce promises. Debouncing is a technique to limit the rate at which a function is executed, ensuring that it is only called once within a specified time frame, even if it is triggered multiple times.

What are @types/debounce-promise's main functionalities?

Basic Debouncing

This feature allows you to debounce a promise-returning function. In this example, the fetchData function is debounced with a delay of 2000 milliseconds. Even if debouncedFetchData is called multiple times, the fetchData function will only be executed once within the 2-second window.

const debounce = require('debounce-promise');

const fetchData = () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve('Data fetched');
    }, 1000);
  });
};

const debouncedFetchData = debounce(fetchData, 2000);

debouncedFetchData().then(console.log); // 'Data fetched' after 2 seconds

Immediate Execution

This feature allows you to execute the debounced function immediately on the leading edge of the timeout. In this example, the fetchData function is executed immediately when debouncedFetchData is called, and subsequent calls within the 2-second window will be ignored.

const debounce = require('debounce-promise');

const fetchData = () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve('Data fetched');
    }, 1000);
  });
};

const debouncedFetchData = debounce(fetchData, 2000, { leading: true });

debouncedFetchData().then(console.log); // 'Data fetched' immediately

Cancel Debounced Function

This feature allows you to cancel a debounced function before it gets executed. In this example, the debouncedFetchData function is canceled before it can execute the fetchData function.

const debounce = require('debounce-promise');

const fetchData = () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve('Data fetched');
    }, 1000);
  });
};

const debouncedFetchData = debounce(fetchData, 2000);

debouncedFetchData().then(console.log); // 'Data fetched' after 2 seconds

debouncedFetchData.cancel(); // Cancels the debounced function

Other packages similar to @types/debounce-promise

FAQs

Package last updated on 07 Nov 2023

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