Created
September 4, 2014 11:51
-
-
Save gr2m/5ad1186046c9f68e8a33 to your computer and use it in GitHub Desktop.
How to achive the logic below with the native JavaScript Promise implementation?
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
var requestPromise; | |
function getCurrentState() { | |
// prevent sending multiple GET requests to /state.json. If one is pending, return its promise | |
if (requestPromise.isPending()) return requestPromise; | |
requestPromise = ajaxRequestReturningPromise('GET', '/state.json'); | |
return requestPromise; | |
} | |
promise1 = getCurrentState() | |
promise2 = getCurrentState() | |
// promise1 & promise2 send only one GET /state.json |
jaz303
commented
Sep 4, 2014
for reference, @jcoglan's fork https://gist.github.com/jcoglan/ff49998991022aad4e22
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment