debounce-promises
v1.0.4
Published
``` npm i debounce-promises ```
Downloads
8
Readme
INSTALL
npm i debounce-promises
USAGE
commonJS: const { debouncePromise } = require('debounce-promises'); EsModules: import { debouncePromise } from 'debounce-promises';
PARAMS
Arg-1: Async function
Args-2: Debounce time or cooling time in milli seconds
EXAMPLE
Some expensive function in your code
const expensiveFunction = (arg1) =>
new Promise((res) => {
setTimeout(() => {
res(arg1);
}, 2000);
});
Add debounce wrapper for your function
const test = debouncePromise(expensiveFunction, 90);
use that wrapper in multiple places
test([1, 2, 3]).then((res) => console.log(res));
test([4, 5, 6]).then((res) => console.log(res));
test([7, 8, 9]).then((res) => console.log(res));
output
[1,2,3,4,5,6,7,8,9]