Skip to content
Debounce promise-returning & async functions
JavaScript TypeScript
Branch: master
Clone or download
Latest commit b213e79 Apr 5, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Require Node.js 6, add TypeScript definition (#5) Mar 12, 2019
.gitattributes Require Node.js 6, add TypeScript definition (#5) Mar 12, 2019
.gitignore
.npmrc
.travis.yml Require Node.js 6, add TypeScript definition (#5) Mar 12, 2019
index.d.ts Tiny TS definition tweak Apr 5, 2019
index.js Refactor TypeScript definition to CommonJS compatible export (#6) Apr 5, 2019
index.test-d.ts Refactor TypeScript definition to CommonJS compatible export (#6) Apr 5, 2019
license Meta tweaks Mar 12, 2019
package.json 2.1.0 Apr 5, 2019
readme.md Meta tweaks Mar 12, 2019
test.js Meta tweaks Mar 12, 2019

readme.md

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

You can’t perform that action at this time.