I have this code:
function ProductObj(product, i) {
var self = this;
self.photo = product.photos.medium_half;
self.title = product.name;
self.tagline = product.tagline;
self.url = product.url;
self.htmlView = "";
self.index = i;
//this async call is slow, very slow
self.updateHTML = function() {
return new Promise(resolve => {
$.get('product-template.html', function (template) {
self.htmlView = template.replace('{image}', self.photo)
.replace('{title}', self.title)
.replace('{tagline}', self.tagline)
.replace('{url}', self.url);
console.log('updateHTML ' + self.index + ' ran');
resolve();
});
});
};
}
when self.updateHTML is called, self.updateDOM is called at the same time
self.updateDOM = function() {
return new Promise(resolve => {
var thisHTML = '';
for( var i = 0; i < self.products.length; i++) {
if (i % 3 === 0 ) {
thisHTML += "<div class='row'>";
console.log('START')
}
thisHTML += self.products[i].htmlView;
if ((i % 3 === 2) || i === (self.products.length - 1) ) {
thisHTML += "</div>";
console.log('finish')
}
if(i === (self.products.length -1)) {
$("#content").append(thisHTML);
}
}
resolve();
})
}
naturally, I used promises to attempt to fix this as such
page.getProducts('data.json')
.then( page.updateProductHTML )
.then( page.updateDOM )
.then( someOtherFunction );
Page.getProducts executes first and returns a promise to page.updateProductHTML. So far my promise in page.updateProductHTML is resolving before assignments can finish in self.updateHTML and updateDOM is firing but it needs values from updateHTML before it can finish
The problem arises from this page.updateProductHTML as it runs this code
self.updateProductHTML = function() {
return new Promise(resolve => {
for( var i = 0; i < self.products.length; i++){
self.products[i].updateHTML();
}
resolve();
})
};
I attempted to wrap the above code in a promise and resolve outside of the for loop but the $.get() call is still working
from what I understand I need to keep updateHTML in a promise but it doesn't seem to do anything different in its present state since I can't use a .then in my for loop in page.updateProductHTML
How do I force page.updateProductHTML to not resolve until it finishes its calls in self.updateHTML?
small recap I want this order self.getProducts() => self.updateProducts => sef.updateDOM => other functions
You should use Promise.all():
self.updateProductHTML = function() {
return Promise.all(self.products.map(product => product.updateHTML()));
};
You could use promise.all, which waits till all of your promises are resolved and then executes the other methods which are dependent on the earlier methods.
An example is here on my Codepen link
self.updateProductHTML = function() {
var updateMethods = [];
for (var i = 0; i < self.products.length; i++) {
updateMethods.push(self.products[i].updateHTML());
}
return Promise.all(updateMethods);
}
self.updateDOM = function() {
for (var i = 0; i < self.products.length; i++) {
if (i % 3 === 0) {
thisHTML += "<div class='row'>";
console.log('START')
}
thisHTML += self.products[i].htmlView;
if ((i % 3 === 2) || i === (self.products.length - 1)) {
thisHTML += "</div>";
console.log('finish')
}
if (i === (self.products.length - 1)) {
$("#content").append(thisHTML);
}
}
}
updateProductHTML().then(updateDOM);
Related
I am trying to get a bunch of ID's from an API and then form a sequence of requests which would make further calls to an API to fetch some parameters. These would be totaled and i expect the output results to be pushed as JSON array.
The problem is REST call is async and i've put a promise but not sure when to resolve the promise back to the calling function, the rest call some times take a second or 2 to respond back.
I would like know at what point can i resolve the promise or how to know when the totals have been computed ?
The Route
app.get("/sonar/:x_id",function(req,resp) {
getRestSonar(req.params.x_id).then(function (fromResolve) {
resp.send(fromResolve);
});
});
The function with promise which makes the rest call loops
var getRestSonar = function(requestX) {
return new Promise(function(resolve,reject) {
var unirest = require("unirest");
var reqx = unirest("GET", "http://sonarqubexxServer/api/projects");
var outputJson = {
table: []
};
reqx.end(function (res) {
if (res.error) throw new Error(res.error);
// console.log(res.body);
var result = res.body;
//var needle = req.params.csi_id;
var needle = requestX;
var TotalDuplicateLines = 0;
var TotalBugs = 0;
var TotalNcloc = 0;
var TotalCodeSmells = 0;
var TotalVulnerabilities = 0;
for (var i=0;i<result.length;i++) {
if (result[i].nm.indexOf(needle) !== -1) {
console.log(result[i].k);
var queryUrl = "http://sonarqubexxServer/api/resources?resource="+result[i].k+"&metrics=code_smells,bugs,vulnerabilities,ncloc,coverage,duplicated_lines&format=json"
console.log(queryUrl);
var subrequest = unirest("GET",queryUrl);
subrequest.end(function (resXX) {
if (resXX.error);
var resXXResult = resXX.body;
for (var i=0;i<resXXResult.length;i++) {
// var duplicateData = resXXResult[0].msr.filter(item => item.key == 'duplicated_lines');
resXXResult[i].msr.forEach(m => {
if (m.key === 'duplicated_lines') {
console.log('Duplicated Lines ' + m.val);
TotalDuplicateLines += m.val;
}
else if(m.key === 'bugs' ) {
console.log('Bugs ' + m.val);
TotalBugs += m.val;
}
else if(m.key === 'ncloc' ) {
console.log('Lines of Code ' + m.val);
TotalNcloc += m.val;
}
else if(m.key === 'code_smells' ) {
console.log('Code Smells ' + m.val);
TotalCodeSmells += m.val;
}
else if(m.key === 'vulnerabilities' ) {
console.log('Vulnerabilities ' + m.val);
TotalVulnerabilities += m.val;
outputJson.table.push({totduplines:TotalDuplicateLines},{totVul:TotalVulnerabilities});
}
});
console.log("Iam here with I :: " + i);
if (i === (resXXResult.length - 1)) {
//Should i resolve here makes no sense
console.log("Resolved the promise now..");
}
//The for ends here
}
// I see this is a bad place to resolve..
resolve(outputJson);
});
}
}
});
});
}
EDIT : As suggested in the comments, split the calls into smaller
sections
Now, i fetch the api calls seperatly create an array out of it, then use promises to call back to the API ? how do i resolve each call by looping over it ?
When i try to loop it always resolves request[0] and then comes out of the promise, how can i create a promise array and wait for them to complete ?
app.get("/sonar/:csi_id",function(req,resp) {
var collectiveResult = [];
getRestSonar(req.params.csi_id).then(function (fromResolve) {
return splitReqUrl(fromResolve);
}).then(function(fromSplitUrl) {
console.log("I am from split url ::::" + fromSplitUrl);
return getSubSonarProperties(fromSplitUrl);
}).then(function(fromsubSonar) {
collectiveResult.push(fromsubSonar);
console.log("+++++++++++++++++++++++++++");
console.log(fromsubSonar);
resp.send(collectiveResult);
});
});
var getSubSonarProperties = function(getUrl) {
return new Promise(function(resolve,reject) {
var getSubRest = require("unirest");
console.log("Attempting to GET " + getUrl);
var req = getSubRest("GET",getUrl);
var outputJson = {
table: []
}
var TotalDuplicateLines = 0;
var TotalBugs = 0;
var TotalNcloc = 0;
var TotalCodeSmells = 0;
var TotalVulnerabilities = 0;
req.end(function (res) {
if (res.error);
var resXXResult = res.body;
resolve(resXXResult);
});
});
}
var splitReqUrl = function(request) {
return new Promise(function(resolve,reject) {
resolve(request[1]);
//for(var i=0; i< request.length; i++) {
// resolve(request[i]);
//}
});
}
var getRestSonar = function(requestX) {
return new Promise(function(resolve,reject) {
var unirest = require("unirest");
var reqx = unirest("GET", "http://sonarqubexxx/api/projects");
var outputJson = {
table: []
};
reqx.end(function (res) {
if (res.error) throw new Error(res.error);
// console.log(res.body);
var result = res.body;
//var needle = req.params.csi_id;
var needle = requestX;
var queryArray = [];
for (var i=0;i<result.length;i++) {
if (result[i].nm.indexOf(needle) !== -1) {
console.log(result[i].k);
var queryUrl = "http://sonarxxx/api/resources?resource="+result[i].k+"&metrics=code_smells,bugs,vulnerabilities,ncloc,coverage,duplicated_lines&format=json"
//console.log(queryUrl);
queryArray.push(queryUrl);
}
if (i === (result.length - 1)) {
resolve(queryArray);
}
}
});
});
}
Problem
First of all the problem with your solution is that you're trying to make everything inside a single big new Promise(...) creator.
Even if you manage to make that work it's still a common anti-pattern as Promises are made to be chained using the .then(...) method.
As pointed out by Roamer-1888 there oughta be a fork of unirest that handles Promises directly instead of requiring callbacks as in your example, but let's stick with your version of unirest here.
Solution
So what you need to be doing is create a Promise chain to handle the different steps of your code and pass the results down the chain.
Your steps seem to be:
Make the first call to retrieve initial results.
Filter the results based on the requestX input.
For each item left, make several calls to obtain more data.
Put everything back into an outputJson object.
Basically the only async steps are 1 and 3, but it might be ok to add a third step to build your outputJson and pass it downstream.
So let's start with the first step.
1. Make the first call
In the first link of the Promise chain we need to retrieve the initial results with your first unirest call:
new Promise((resolve, reject) => {
unirest("GET", "http://sonarqubexxServer/api/projects")
.end((res) => {
if (res.error) {
reject(res.error);
} else {
resolve(res.body);
}
});
})
See in this example I already checked if the response contains an error and fired a rejection in that case, otherwise I resolve the promise with the body (the data we need).
The Promise we created above will throw an error if the request fails, and will downstream the body of the response if everything goes fine.
2. Filtering and Sub-calls
Now then we can go ahead and use the full potential of Promises with the .then(...) method:
new Promise((resolve, reject) => {
unirest("GET", "http://sonarqubexxServer/api/projects")
.end((res) => {
if (res.error) {
reject(res.error);
} else {
resolve(res.body);
}
});
}).then((results) => {
results = results.filter((result) => {
return result.nm.indexOf(request) != -1;
});
return Promise.all(results.map((result) => {
return new Promise((resolve, reject) => {
var queryUrl = "http://sonarqubexxServer/api/resources?resource=" + result.k + "&metrics=code_smells,bugs,vulnerabilities,ncloc,coverage,duplicated_lines&format=json"
unirest("GET", queryUrl)
.end((res) => {
if (res.error) {
reject(res.error);
} else {
resolve(res.body);
}
});
})
}))
})
In this step I used some Array methods to make the code cleaner and Promise.all to handle several promises together.
Array.filter is a method which iterates an array and checks for each item if it should be kept in the filtered output or not. So, in your case, we want to keep only those items where result.nm.indexOf(request) != -1.
Array.map is a method which iterates an array and converts each item to something else. Basically the function you provide takes each item as input, converts it to something else and then replaces this new value to the old one in the output array.
Finally Promise.all accepts an array of Promises and returns a Promise itself. This returned Promise will resolve when all the given Promises resolve and will pass downstream an array which items are the results of each single Promise.
So by writing Promise.all(results.map((results) => { return new Promise(...) })) we convert each result in the results array into a Promise that executes the result-specific call and put it into the output array of Promises which is fed to Promise.all so they get executed at once.
3. Build the outputJSON
Now the Promise chain outputs the result of Promise.all which is an array of all the results of each Promise, which are the results of each sub-call.
We can then simply take the downstream data and use your nested iterations to build the outputJSON to be passed downstream:
new Promise((resolve, reject) => {
unirest("GET", "http://sonarqubexxServer/api/projects")
.end((res) => {
if (res.error) {
reject(res.error);
} else {
resolve(res.body);
}
});
}).then((results) => {
results = results.filter((result) => {
return result.nm.indexOf(request) != -1;
});
return Promise.all(results.map((result) => {
return new Promise((resolve, reject) => {
var queryUrl = "http://sonarqubexxServer/api/resources?resource=" + result.k + "&metrics=code_smells,bugs,vulnerabilities,ncloc,coverage,duplicated_lines&format=json"
unirest("GET", queryUrl)
.end((res) => {
if (res.error) {
reject(res.error);
} else {
resolve(res.body);
}
});
})
}))
}).then((allResults) => {
var TotalDuplicateLines = 0;
var TotalBugs = 0;
var TotalNcloc = 0;
var TotalCodeSmells = 0;
var TotalVulnerabilities = 0;
var outputJson = {
table: []
};
for (var i = 0; i < allResults; i++) {
for (var j = 0; j < allResults[i].length; j++) {
allResults[i][j].msr.forEach(m => {
if (m.key === 'duplicated_lines') {
TotalDuplicateLines += m.val;
}
else if (m.key === 'bugs') {
TotalBugs += m.val;
}
else if (m.key === 'ncloc') {
TotalNcloc += m.val;
}
else if (m.key === 'code_smells') {
TotalCodeSmells += m.val;
}
else if (m.key === 'vulnerabilities') {
TotalVulnerabilities += m.val;
outputJson.table.push({ totduplines: TotalDuplicateLines }, { totVul: TotalVulnerabilities });
}
});
}
}
return outputJson;
})
If your return this long Promise chain in your getRestSonar(request) function, then you could write getRestSonar(request).then((outputJson) => { ... do something with your outputJson ... })
In following code with 100000 records recursiveFnReturnsPromiseV1 executes fine while recursiveFnReturnsPromiseV2 fails with out of stack exception. The only difference between two is the way promises are being recursed. In the v1, the recursion is within a "then" of the first promise while in v2, the recursion is within the original promise itself. What's the difference?
let aValues = Array(100000);
recursiveFnReturnsPromiseV1(aValues, 0).then(function() {
let p = document.createElement('div');
p.innerText = 'recursiveFnReturnsPromiseV1 finished';
document.getElementById('v1').appendChild(p);
}, function() {
let p = document.createElement('div');
p.innerText = 'recursiveFnReturnsPromiseV1 failed';
document.getElementById('v1').appendChild(p);
})
recursiveFnReturnsPromiseV2(aValues, 0)
.then(function() {
let p = document.createElement('div');
p.innerText = 'recursiveFnReturnsPromiseV2 finished';
document.getElementById('v2').appendChild(p);
}, function() {
let p = document.createElement('div');
p.innerText = 'recursiveFnReturnsPromiseV2 failed';
document.getElementById('v2').appendChild(p);
})
function recursiveFnReturnsPromiseV1(pValues, ix) {
if (pValues.length <= ix)
return Promise.resolve();
return new Promise(function(c, e) {
document.getElementById('v1').innerText = ix + 'v1' + Date.now();
c();
}).then(function() {
return recursiveFnReturnsPromiseV1(pValues, ++ix);
})
}
function recursiveFnReturnsPromiseV2(pValues, ix) {
if (pValues.length <= ix)
return Promise.resolve();
return new Promise(function(c, e) {
document.getElementById('v2').innerText = ix + 'v2' + Date.now();
recursiveFnReturnsPromiseV2(pValues, ++ix).then(function() {
c();
}, function(err) {
e()
});
})
}
<div id='v1'></div>
<div id='v2'></div>
Lets strip away the Promise constructor antipattern, and use a simple Promise.resolve instead. Your functions now become
function recursiveFnReturnsPromiseV1(pValues, ix) {
if (pValues.length <= ix)
return Promise.resolve();
let p = document.createElement('div');
p.innerText = ix + 'v1' + Date.now();
document.getElementById('v1').appendChild(p);
return Promise.resolve().then(function() {
return recursiveFnReturnsPromiseV1(pValues, ++ix);
})
}
function recursiveFnReturnsPromiseV2(pValues, ix) {
if (pValues.length <= ix)
return Promise.resolve();
let p = document.createElement('div');
p.innerText = ix + 'v2' + Date.now();
document.getElementById('v2').appendChild(p);
return Promise.resolve(recursiveFnReturnsPromiseV2(pValues, ++ix));
}
It should be obvious by now why the second function overflows the stack.
Why doesn't the first as well? Because the recursive call is inside an asynchronous then callback, which means it starts later (after the outer call returned) with a fresh call stack.
I am new to using Promise and breaking my head to solve this. I want to run a script until a condition is met in protractor with below code but it's not working. how to fix this?
let counter = 30;
for (let i = 0; i < counter; i++) {
browser.executeScript(somescript).then((value) => {
//console.log(value);
if (value > 0)
//do some stuff
}
else {
return; //exit for loop --not working
//or
i=counter;// to exit if i and counter value same
}
})
}
I have this limitedRetry code that would appear to be what you need
limitedRetry = (cont, fn) => fn().catch(err => cont > 0 ? limitedRetry(cont - 1, fn) : Promise.reject(err));
Your use would be
limitedRetry(30, function() {
browser.executeScript(somescript).then((value) => {
if (value > 0) {
// do some stuff
return 'this will be the resolved value of the promise';
} else {
return Promise.reject('try again');
}
});
})
.then(v => console.log(v))
.catch(err => console.log(err));
Now you're firing all executeScripts at the same time, and in the worst case the last script (result) may return first. You should start the next executeScript only if you have the result of the previous executeScript.
This can be done by 'listening' to the result of the previous promise, and calling executeScript after you know what the previous result was. I've replaced somescript with the variable i, so that the result is more determinate. In case you're just looking for a retry, see the other answer.
var browser = {
executeScript: function(i) {
return Promise.resolve(i);
}
}
var initial = Promise.resolve(null);
for (var i = 0; i < 30; i++) {
(function(locali) {
initial = initial.then(function(prev) {
if(prev === undefined) return;
return browser.executeScript(locali).then(function (value) {
console.log(value);
if (value < 5) {
return value;
} else {
return;
}
});
});
})(i);
}
I have a angular service inside a for loop that returns an array of object. I want to get the summation of the value returned by that service but I got nothing in the end. My service works fine but my problem is I can't get the summation. Below is my code
controller
var TotalOBValueLand = 0;
for(var i = 0; i < $scope.selectedProp.length; i++){
AccountService.getTopAccountDetails($scope.selectedProp[i]["propId"]).then(function(msg){
TotalOBValueLand += parseInt(msg.data[0].OBValueLand);
//my return data here has no error.
});
}
console.log(TotalOBValueLand); //I got zero;
Use Promise.all and array#map to get an array of results, then use Array#reduce to sum them up
var TotalOBValueLand = 0;
Promise.all($scope.selectedProp.map(function(prop) {
return AccountService.getTopAccountDetails(prop).then(function(msg){
return parseInt(msg.data[0].OBValueLand);
});
})).then(function(results) {
TotalOBValueLand = results.reduce(function(a, b) {
return a + b;
});
console.log(TotalOBValueLand);
});
In response to the comments
var TotalOBValueLand = 0;
var TotalOBValueBuilding = 0;
Promise.all($scope.selectedProp.map(function(prop) {
return AccountService.getTopAccountDetails(prop).then(function(msg){
return parseInt(msg.data[0]);
});
})).then(function(results) {
TotalOBValueLand = results.reduce(function(a, b) {
return a.OBValueLand + b.OBValueLand;
});
TotalOBValueBuilding = results.reduce(function(a, b) {
return a.OBValueBuilding + b.OBValueBuilding ;
});
console.log(TotalOBValueLand, TotalOBValueBuilding);
});
and a little more generic
Promise.all($scope.selectedProp.map(function(prop) {
return AccountService.getTopAccountDetails(prop).then(function(msg){
return parseInt(msg.data[0]);
});
})).then(function(results) {
var totals = results.reduce(function(result, a) {
Object.keys(a).forEach(function(key) {
result[key] = (result[key] || 0) + a[key];
});
return result;
}, {});
console.log(totals.OBValueLand, totals.OBValueBuilding);
});
You cannot access console.log(TotalOBValueLand); outside the response since .getTopAccountDetails() is asynchronous, it will be always 0.
try to wrap it inside,
var TotalOBValueLand = 0;
for(var i = 0; i < $scope.selectedProp.length; i++){
AccountService.getTopAccountDetails($scope.selectedProp[i]["propId"]).then(function(msg){
TotalOBValueLand += parseInt(msg.data[0].OBValueLand);
console.log(TotalOBValueLand);
});
}
The problem is that you are mixing asynchronous and synchronous functions. This should demonstrate what is going on a little for you
https://jsfiddle.net/Austio/v7goqk4d/
AccountService = {
getTopAccountDetails: function() {
return new Promise((resolve) => resolve(1))
}
}
var TotalOBValueLand = 0;
for(var i = 0; i < 2; i++){
AccountService.getTopAccountDetails().then(function(x){
TotalOBValueLand += x;
console.log('incremented async', TotalOBValueLand)
});
}
console.log('sync', TotalOBValueLand);
setTimeout(() =>
console.log('timeout', TotalOBValueLand), 2000)
Solution using an array of promises that we resolve
var TotalOBValueLand = 0;
promises = []
for(var i = 0; i < 2; i++){
promise = AccountService
.getTopAccountDetails()
promises.push(promise)
}
console.log('before', TotalOBValueLand);
Promise
.all(promises)
.then(results => {
TotalOBValueLand = results.reduce((curr,acc) => curr + acc, 0);
console.log('done', TotalOBValueLand);
return TotalOBValueLand;
})
.catch(err => 'handle me')
Hi all I have this working method to call an array of functions at recurring intervals.
Here you can see the object with the methods to add/remove functions in the array and the functions to start/stop the calling interval. (You have to focus only to the start method but I put them all for clarification)
function updateEngine() {
var _callRecurringFunctions = null,
_functionsToCall = [],
_functionIds = [],
_functionApps = [];
updateEngine.prototype.addFunction = function (appCode, funcId, func) {
if ($.isFunction(func) &&
$.inArray('_' + appCode + '_' + funcId, _functionIds) == -1) {
_functionApps.push(appCode);
_functionIds.push('_' + appCode + '_' + funcId);
_functionsToCall.push(func);
}
}
updateEngine.prototype.removeFunction = function (appCode, funcId) {
if (funcId == null) { // remove all functions relative to an app
for (var x = 0; x < _functionApps.length; x++) {
if (_functionApps[x] == appCode) {
_functionApps.splice(x, 1);
_functionIds.splice(x, 1);
_functionsToCall.splice(x, 1);
}
}
}
else { // remove the single app function
var pos = $.inArray('_' + appCode + '_' + funcId, _functionIds);
if (pos >= 0) {
_functionApps.splice(pos, 1);
_functionIds.splice(pos, 1);
_functionsToCall.splice(pos, 1);
}
}
}
updateEngine.prototype.start = function () {
_callRecurringFunctions = setInterval(function () {
for (var x = 0; x < _functionsToCall.length; x++) {
var frame = null;
// id == -1: local function
// id == 0: function defined in home iframe
// id > 0: function defined in an app iframe
if (_functionApps[x] >= 0)
frame = _portalContent.find("iframe[id='" + _functionApps[x] + "']");
if (frame != null && frame.get(0) != null) {
var iframeContent = frame.get(0).contentWindow || frame.get(0).contentDocument;
_functionsToCall[x].apply(iframeContent);
}
else
_functionsToCall[x]();
}
}, _updateFrequence); // tick every 5 seconds
}
updateEngine.prototype.stop = function () {
clearInterval(_callRecurringFunctions);
_callRecurringFunctions = null;
_functionApps = [];
_functionIds = [];
_functionsToCall = [];
}
}
I want to convert the start method using setTimeout instead of setInterval and I wrote something like this:
updateEngine.prototype.start = function () {
function doLoop() {
$.when.apply($, _functionsToCall)
.done(function() {
setTimeout(doLoop, _updateFrequence);
});
}
setTimeout(doLoop, _updateFrequence);
}
How can I change the context of the array functions _functionsToCall like I do in the previous method to pass the iframe context to each function?
I've resolved my problem in another way...
Now I have an array of functions that return a promise each;
Those functions can be declared inside differents iframes;
I increase a counter when each promise is resolved, and when all promises are resolved I can start again with another loop.
Obviously on each iteration the array can contains a different number of functions.
I'd like to know if there is a better way to do this task or if there are some issues with my code.
Thank you all.
updateEngine.prototype.start = function () {
function doLoop() {
var count = 0,
functionsCount = _functionsToCall.length
for (var x = 0; x < functionsCount; x++) {
var frame = null;
// id == -1: local function
// id >= 0: function defined in iframe
if (_functionApps[x] >= 0)
frame = _portalContent.find("iframe[id='" + _functionApps[0] + "']");
if (frame != null && frame.get(0) != null) {
var iframeContent = frame.get(0).contentWindow || frame.get(0).contentDocument;
$.when.apply(iframeContent, _functionsToCall[x]())
.done(function () {
count++;
})
.fail(function () {
count++;
console.log("err")
})
.always(function () {
if (count == functionsCount)
setTimeout(doLoop, _updateFrequence)
})
}
else
$.when(_functionsToCall[x]())
.done(function () {
count++;
})
.fail(function () {
count++;
console.log("err")
})
.always(function () {
if (count == functionsCount)
setTimeout(doLoop, _updateFrequence)
})
}
}
setTimeout(doLoop, _updateFrequence)
}