Hey there, I'm working on a code snippet to check the status of a Rails model. Here's what I have so far:
var intervalCall = setInterval(function(){
$.post("getstatus", {id:id});
var finished = "<%= @sentence.finished%>";
// CONDITION ONE: STOP INTERVAL WHEN THIS HAPPENS LATER
if ("<%= @sentence.result %>"){
clearInterval(intervalCall);
state_2();
}
// CONDITION TWO: KEEP INTERVAL RUNNING AFTER THIS EARLIER EVENT
else if (String(finished)== "true"){
state_1();
}
},3000);
intervalCall;
I'm looking for suggestions on how to better structure this flow. Any ideas?
Thanks in advance!