Created
November 26, 2018 05:02
-
-
Save graup/8c871fe64171c49efea05650cc80a7bc 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
const SLOW_LOAD_TIME = 1500; | |
function waitOrLoad(callbackIfSlow, maximumLoadTime = SLOW_LOAD_TIME) { | |
const timeout = setTimeout(callbackIfSlow, maximumLoadTime); | |
return function loadingFinished() { | |
clearTimeout(timeout); | |
} | |
} | |
async function doSomething() { | |
const loadingFinished = waitOrLoad(() => { | |
console.log('loading is slow'); | |
}); | |
// do something that the user expects to take some time, e.g. loading data ... | |
loadingFinished(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment