Created
December 20, 2018 22:20
-
-
Save gabemeola/24e7f8c28745a5e2d328cd575131c621 to your computer and use it in GitHub Desktop.
Resolves passed function after timeout
This file contains hidden or 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
/** | |
* Resolves passed function after timeout | |
* | |
* @param {number} timeout | |
* @param {Function} fn | |
* @return {Promise<any>} | |
*/ | |
export default function wait(timeout, fn) { | |
return new Promise((resolve) => { | |
setTimeout(() => resolve(fn()), timeout); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment