bjoerge / debounce-promise

Create a debounced version of a promise returning function
MIT License
241 stars 27 forks source link

Doesn't work for promises / async functions #26

Closed TylerRick closed 1 year ago

TylerRick commented 4 years ago

Example:

  const debounceFunc = debounce(1000, async (num) => {
    console.log('num:', num);
  });
debounceFunc(1)

Results in error:

Uncaught TypeError: Cannot read property 'apply' of undefined

I guess I'll be trying out https://www.npmjs.com/package/debounce-promise instead...

ajinkyapisal commented 3 years ago

Your parameter order is wrong. The first parameter is a function. Try this code.

const debounceFunc = debounce(async (num) => {
    console.log('num:', num);
}, 1000);
debounceFunc(1)