Reputation: 1931
Here is a 'hypothetical' situation.
Let's say I have :
a websocket who tell's me to send a ajax on a url like http://localhost/Whatever
every 10 sec.
The ajax call on http://localhost/Whatever
will take 45 seconde to reply (exagerate number for the situation).
I wonder how will the browser react? in my mind 3 case:
abort()
on the
Ajax 1st call and start a new one (if the browser really does that, it
would be rubbish in my mind).So, Which case will happen and why ?
Upvotes: 0
Views: 1216
Reputation: 13570
The answer is case 3.
The browser will send all requests in the order you make them. Generally speaking a computer will carry out your instructions in the order your issue them. If you want or need special behavior such as throttling the rate of the requests or not sending the subsequent requests until prior ones have finished you will need to implement that your self.
Upvotes: 2
Reputation: 3464
Imho, this pseudocode might help you.
var requestLock = false;
function pollFromSocket() {
if (someCondition) {
sendRequest();
}
}
function sendRequest() {
if (requestLock) {
return;
}
requestLock = true;
$.get('/whatever')
.done(function(response) {
// process response
})
.always(function() {
requestLock = false;
});
}
Upvotes: 1