bjoerge / debounce-promise

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

then is not a function #28

Closed vaske closed 3 years ago

vaske commented 3 years ago

Hi @bjoerge,

I have one issue with debounce function, here is what I'm doing

const fakeResponseFunc = ({ status, data}) => {
  return new Promise((resolve, reject) => resolve({ status, data })
};

function expensiveOperation() {
  return Promise.resolve(fakeResponseFunc({
      status: 200,
      data: "something",
    }))
    }

const afterDebounce = debounce(expensiveOperation, 300);

afterDebounce.then(({ data }) => console.log(data))

I'm getting for afterDebounce.then is not a function, I use latest v3.1.2 version this is really basic sample and weird that it doesn't do debounce as desired.

bjoerge commented 3 years ago

debounce returns a function, try afterDebounce().then(({ data }) => console.log(data))