Hi I have the following code, that checks for Rails model status
var intervalCall = setInterval(function(){
$.post("getstatus", {id:id});
var finished = "<%= @sentence.finished%>";
//THIS IS CONDITION ONE, IT IS LIKELY TO HAPPEN LATER AND I WANT TO STOP THE SETINTERVAL
if ("<%= @sentence.result %>"){
clearInterval(intervalCall);
state_2();
}
//THIS IS CONDITION TWO, IT IS LIKELY TO HAPPEN EARLIER AND I WANT
// TO KEEP THE SETINTERVAL RUNNING AFTER IT"S MET
else if (String(finished)== "true"){
state_1();
}
},3000);
intervalCall;
What would be the best way to organize this kind of flow?
Thanks in advance!
some update