Created
April 16, 2020 06:13
-
-
Save mattisa/4eca326a16549c4480ba5e8594f95c38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function debouncePromise(fn, delay) { | |
let time = null; | |
return (...args) => { | |
if (time) { | |
clearTimeout(time); | |
} | |
return new Promise((res, rej) => { | |
time = setTimeout(() => { | |
fn.apply(null, args) | |
.then((...resArgs) => res.apply(null, resArgs)) | |
.catch(e => rej(e)); | |
}, delay); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment