2
Is there any way to run more than one setInterval() at the same time?
In this my code, if I run twice the function "interval" the program goes into infinite loop and the console gets:
[1,2,3,4,5]
[1,2,3,4,5,6]
[1,2,3,4,5,6,7]
[1,2,3,4,5,6,7,8......] infinitely
arraya = []
arrayb = []
function interval(array, length, count) {
a = setInterval(function () {
count++;
array.push(count);
if (array.length > length) {
console.log(array.join(' '));
clearInterval(a);
}
}, 150);;
}
interval(arraya, 4, 0);
// interval(arrayb, 9, 0)
It seemed to me a kind of similar doubt: http://answall.com/questions/178944/existe-um-modo-de-cria-uma-execu%C3%A7%C3%A3o-parallel-using-javascript
– MarceloBoni