Within my web worker script, I am utilizing the following code:
self.addEventListener('message', function(e){
try {
var xhr=new XMLHttpRequest()
for(var i = 0; i < e.data.urls.length;i++){
xhr.open('GET', e.data.urls[i], true);
xhr.setRequestHeader('Accept', 'application/json');
xhr.send(null);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200 || xhr.status == 304 || xhr.status ==0) {
postMessage(xhr.responseText);
} else {
postMessage(xhr.status + xhr.responseText);
throw xhr.status + xhr.responseText;
}
}
};
}
} catch (e) {
postMessage("ERROR:"+e.message);
}
}, false);
The array e.data.urls contains 16 separate requests which are received and processed on the UI thread through the following code snippet:
var replies = 0;
worker.addEventListener('message', function(e){
replies += 1;
});
However, only 10 of the requests seem to be completing. I wonder if this is due to the UI thread halting before all responses have been returned, or if there may be another element that I am overlooking?