Skip to content

Instantly share code, notes, and snippets.

@neodigm
Last active December 8, 2020 02:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neodigm/53d36f338b0e1971fa2cc71f175612b0 to your computer and use it in GitHub Desktop.
Save neodigm/53d36f338b0e1971fa2cc71f175612b0 to your computer and use it in GitHub Desktop.
JavaScript PromiseAll ES5 polyfill | Manage async await requests
// 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;
}
}
}
}
})();
@neodigm
Copy link
Author

neodigm commented May 1, 2020

Usage:
oPromiseAll.init({ tokens: ["totals"], fCB: function(){ oEvoCart.refresh(["items"]); } });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment