Skip to content

Instantly share code, notes, and snippets.

@tbjgolden
Created May 8, 2019 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbjgolden/d82380c0bc066d21780b4dfafd8677dc to your computer and use it in GitHub Desktop.
Save tbjgolden/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