JSFiddle - React, Tailwind, and code Playground
HTML
<p>(Disconnect your network temporarily and watch your Net tab if you want to really see things pile up.)</p>
<div id="reqs"></div>
<div id="req2"></div>
JavaScript
var n = 0, t = 0, u = 0, i, s = 'Stopping after 25 requests, to avoid killing jsfiddle’s server';
function a() {
$.post('/ajax_html_echo/', function() {
--n;
});
++n; ++t;
$('#reqs').html(n + ' a() requests in progress!');
if(t > 25)
{
clearInterval(i);
$('#reqs').html(s);
}
}
function b() {
++u;
$.post('/ajax_html_echo/', function() {
$('#req2').html('b(): ' + new Date().toString());
if(u <= 25)
{
setTimeout(b, 500);
}
else
{
$('#req2').html(s);
}
});
}
i = setInterval(a, 500);
setTimeout(b, 500);