Skip to content

Instantly share code, notes, and snippets.

View greathmaster's full-sized avatar
🧐

Hersha Venkatesh greathmaster

🧐
  • San Francisco, Bay Area
View GitHub Profile
@alexnoz
alexnoz / debounce-abort-fetch.js
Created June 13, 2018 20:11
Abort fetching data in a function when debouncing it
function debounceFetch (fn, delay, onCancel = () => {}) {
let timer = 0, isFetching = false
return function (...args) {
clearTimeout(timer)
if (isFetching) {
onCancel()
isFetching = false
}