My implementation of debounce axios request left the promise in pending state forever, is there a better way?
问题 I need a simple debounce function with immediate always true. Without resorting to lodash and with the help of Can someone explain the "debounce" function in Javascript , I implemented it as following, function debounce(func, wait) { var timeout; return function() { if (!timeout) func.apply(this, arguments); clearTimeout(timeout); timeout = setTimeout(()=>{timeout = null}, wait); }; }; It works as expected until I need to debounce axios request. Assumed I have a debounced axios method, I