I have 2 setInterval function (okay guys, sorry, I thought the code inside may be redundant and will make the question become localized :/ but anyway, here it is:
Код: Выделить всё
$('#armStatus').click(function(){
armingloop = setInterval(function () {
if ($checkbox.is(':checked ')) {
$.post('/request', {
key_pressed: "arming_status"
}).done(function (reply) {
$arm.empty().append("The Arming Status is " + reply + "").show();
$arm.show();
});
} else {
$arm.hide();
}
}, 3000);
});
Код: Выделить всё
$('#monitor').click(function () {
bigloop = setInterval(function () {
var checked = $('#status_table tr [id^="monitor_"]:checked');
if (checked.index() === -1 || checked.length === 0) {
clearloop(bigloop);
$('#monitor').button('enable');
} else {
//$('#monitor').button('enable'); //enable the monitor button
(function loop(i) {
//monitor element at index i
monitoring($(checked[i]).parents('tr'));
//delay of 3 seconds
setTimeout(function () {
//when incremented i is less than the number of rows, call loop for next index
if (++i < checked.length) loop(i);
}, 3000);
}(0)); //start with 0
}
}, index * 3000); //loop period
Код: Выделить всё
function clearloop(loopname){
bigloop= window.clearInterval(loopname);
}
Код: Выделить всё
bigloop
Код: Выделить всё
armingloop
Код: Выделить всё
monitoring
Код: Выделить всё
bigloop
Note that I have a
Код: Выделить всё
setTimer
My question here is, how can i make sure any 2
Код: Выделить всё
setInterval
Источник: https://stackoverflow.com/questions/165 ... each-other