Skip to content

Instantly share code, notes, and snippets.

@tmgldn
Created May 8, 2019 06:30
Show Gist options
  • Select an option

  • Save tmgldn/d82380c0bc066d21780b4dfafd8677dc to your computer and use it in GitHub Desktop.

Select an option

Save tmgldn/d82380c0bc066d21780b4dfafd8677dc to your computer and use it in GitHub Desktop.
Lightweight JS promise debounce
const debounce = (func, ms = 500) => {
let timeout;
return function(...args) {
clearTimeout(timeout);
return new Promise(resolve => {
timeout = setTimeout(() => {
resolve(func.bind(this)(...args));
}, ms);
});
};
};
export default debounce;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment