Skip to content

Debounce promise-returning & async functions

License

Notifications You must be signed in to change notification settings

wata-lb/p-debounce

 
 

Repository files navigation

p-debounce Build Status

Debounce promise-returning & async functions

Install

$ npm install p-debounce

Usage

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

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

leading

Type: boolean
Default: false

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

Related

  • 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…

License

MIT © Sindre Sorhus

About

Debounce promise-returning & async functions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 88.3%
  • TypeScript 11.7%