Created
March 21, 2018 13:49
-
-
Save juice49/fe1c2709812b95c93869b5a1bb42551b to your computer and use it in GitHub Desktop.
Promise once (sort of)
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
function promiseOnce () { | |
let promise = null | |
return function (createPromise) { | |
if (promise) { | |
return promise | |
} | |
promise = createPromise() | |
promise.then(() => { | |
promise = null | |
}) | |
return promise | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment