Socket
Socket
Sign inDemoInstall

p-debounce

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    p-debounce

Debounce promise-returning & async functions


Version published
Weekly downloads
90K
decreased by-1.68%
Maintainers
1
Install size
8.17 kB
Created
Weekly downloads
 

Readme

Source

p-debounce

Debounce promise-returning & async functions

Install

$ npm install p-debounce

Usage

import pDebounce from 'p-debounce';

const expensiveCall = async input => input;

const debouncedFn = pDebounce(expensiveCall, 200);

for (const number of [1, 2, 3]) {
	console.log(await debouncedFn(number));
}
//=> 3
//=> 3
//=> 3

API

pDebounce(fn, wait, options?)

Returns a function that delays calling fn until after wait milliseconds have elapsed since the last time it was called.

fn

Type: Function

Promise-returning/async function to debounce.

wait

Type: number

Milliseconds to wait before calling fn.

options

Type: object

before

Type: boolean
Default: false

Call the fn on the leading edge of the timeout. Meaning immediately, instead of waiting for wait milliseconds.

pDebounce.promise(function_)

Execute function_ unless a previous call is still pending, in which case, return the pending promise. Useful, for example, to avoid processing extra button clicks if the previous one is not complete.

function_

Type: Function

Promise-returning/async function to debounce.

import {setTimeout as delay} from 'timers/promises';
import pDebounce from 'p-debounce';

const expensiveCall = async value => {
	await delay(200);
	return value;
}

const debouncedFn = pDebounce.promise(expensiveCall);

for (const number of [1, 2, 3]) {
	console.log(await debouncedFn(number));
}
//=> 1
//=> 2
//=> 3
  • p-throttle - Throttle promise-returning & async functions
  • p-limit - Run multiple promise-returning & async functions with limited concurrency
  • p-memoize - Memoize promise-returning & async functions
  • debounce-fn - Debounce a function
  • More…

Keywords

FAQs

Last updated on 20 Apr 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc