Last active
December 8, 2020 02:13
-
-
Save neodigm/53d36f338b0e1971fa2cc71f175612b0 to your computer and use it in GitHub Desktop.
JavaScript PromiseAll ES5 polyfill | Manage async await requests
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
// Desc: JavaScript PromiseAll ES5 polyfill | Manage async await requests | |
// Usage: oPromiseAll.init({ tokens: ["totals","details"], fCB: function(){ oEvoCart.refresh(["items"]); } }); | |
var oPromiseAll = (function(){ // Manage async await requests | |
var oConfig={}, bInit=false, nCnt=0; | |
return { | |
"init": function( _config ){ | |
oConfig = _config; | |
bInit = true; | |
nCnt=0; | |
}, | |
"update": function( _token ){ | |
if( bInit && (oConfig.tokens.indexOf( _token ) != -1 ) ){ | |
if( ++nCnt === ( oConfig.tokens.length ) ){ | |
oConfig.fCB(); | |
bInit = false; | |
} | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
oPromiseAll.init({ tokens: ["totals"], fCB: function(){ oEvoCart.refresh(["items"]); } });