I am using lodash throttle like this
const throttledFetch = _.throttle(fetch, 10000, { 'leading': false });
I need to trigger this upon a certain notification event I am getting from a ws. So the idea was, if I get 10 notifications at almost the same time, to have the fetch
function fire only once at the wait of 10 seconds.
Instead, what is happening is that the fetch functions gets fired 10 times after the 10 second delay.
How can I fix this? I could use any other methods.
Any suggestion is welcome
Advertisement
Answer
Keep a counter for the invocation and check it for invoking only once.