mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 18:18:56 +00:00
feature(asyncCall) add any count of params
This commit is contained in:
parent
da43ce1ecc
commit
402696deec
1 changed files with 17 additions and 7 deletions
24
lib/util.js
24
lib/util.js
|
|
@ -12,26 +12,36 @@ Util = exports || {};
|
|||
|
||||
Util.asyncCall = function(pFuncs, pOnLoad, pContext) {
|
||||
var i, element, name, func,
|
||||
n = pFuncs.length,
|
||||
funcsCount = pFuncs.length,
|
||||
count = 0,
|
||||
data = [];
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (i = 0; i < funcsCount; i++) {
|
||||
func = pFuncs[i];
|
||||
callCheckFunc(i, func);
|
||||
}
|
||||
|
||||
function checkFunc(pNum, pData) {
|
||||
++count;
|
||||
data[pNum] = pData;
|
||||
var i, m = pData.length,
|
||||
params = [];
|
||||
|
||||
if (count === n)
|
||||
++count;
|
||||
|
||||
if (m >= 2) {
|
||||
for (i = 0; i < m; i++)
|
||||
params[i] = pData[i];
|
||||
|
||||
data[pNum] = params;
|
||||
} else
|
||||
data[pNum] = pData[0];
|
||||
|
||||
if (count === funcsCount)
|
||||
pOnLoad.apply(pContext, data);
|
||||
}
|
||||
|
||||
function callCheckFunc(pNum, pFunc) {
|
||||
Util.exec(pFunc, function(pData) {
|
||||
checkFunc(pNum, pData);
|
||||
Util.exec(pFunc, function() {
|
||||
checkFunc(pNum, arguments);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue