mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-25 08:54:10 +00:00
feature(util) add asyncCall
This commit is contained in:
parent
21055537d8
commit
d22bef234c
2 changed files with 65 additions and 37 deletions
26
lib/util.js
26
lib/util.js
|
|
@ -10,6 +10,32 @@ Util = exports || {};
|
|||
|
||||
var Scope = exports ? global : window;
|
||||
|
||||
Util.asyncCall = function(pFuncs, pOnLoad, pContext) {
|
||||
var i, element, name, func,
|
||||
n = pFuncs.length,
|
||||
count = 0,
|
||||
data = [];
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
func = pFuncs[i];
|
||||
callCheckFunc(i, func);
|
||||
}
|
||||
|
||||
function checkFunc(pNum, pData) {
|
||||
++count;
|
||||
data[pNum] = pData;
|
||||
|
||||
if (count === n)
|
||||
pOnLoad.apply(pContext, data);
|
||||
}
|
||||
|
||||
function callCheckFunc(pNum, pFunc) {
|
||||
Util.exec(pFunc, function(pData){
|
||||
checkFunc(pNum, pData);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/** setting function context
|
||||
* @param {function} pFunction
|
||||
* @param {object} pContext
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue