When reading an article about Long Polling, I got a little confused between the following two options for setInterval
1 -
setInterval(function(){ $.ajax({ url: "server", success: function(data){
2-
(function poll() { setTimeout(function() { $.ajax({ url: "server", success: function(data) { sales.setValue(data.value); }, dataType: "json", complete: poll }); }, 30000); })();
As the blog says, he talks about the second fragment,
Therefore, this pattern does not guarantee execution at a fixed interval per se. But ensures that the previous interval is completed before the next interval is called .
Why does the second passage ensure that the previous interval is completed?
I know about the first (event loops), but got a little confused in the second fragment.
source share