Discussions » Greasy Fork Feedback
Help with making a function wait until all GM_xmlhttpRequest requests are fully completed
The simplest solution would be to check if the currently processed index is the last in xhr onload function:
function retrieveValues(url, index) {
var thisIndex = index;
...............
xhr.onload = function(r) {
.............
if (thisIndex == unique.length -1) {
onComplete();
}
};
................
xhr.send();
}
function onComplete() {
for (i = 0; i < unique.length; i++) { // Filters the irrelevant bugs out
filterBugs(unique[i],i);
}
................
}
There's a lot of info and examples you can find on different methods for the asynchronous code.
Thanks a lot for your reply.
(I'd prefer the synchronous mode for now, as it's simpler)
So, I updated the code, according to your suggestion,
(I omitted the send command -- I initially tried adding details.send(); but it gave details.send is not a function )
but the issue unfortunately remains.
As for synchronous XHR, stop using it, it's very bad and on its way to being deprecated.
The issue in your code is probably because you didn't make i local as shown in my example.
I've just finished the script Mozilla Mercurial - Filters changelogs:
based on your advice now works in async mode, too.
Thanks a lot for your help!
PS. You're so right: sync mode is very bad

Help with making a function wait until all GM_xmlhttpRequest requests are fully completed
I've been trying to make a script that generates a list of only the bugs related to Firefox for desktop in Mozilla Mercurial pushlogs.
It's basically an attempt to create lists similar to the "The Official Win32 xxxxxxx builds" found in Firefox Builds • mozillaZine Forums but for any date interval.
It's this: Mozilla Mercurial - Filters changelogs(pushlogs)
(I've set it as 'unlisted' for obvious reasons)
In it's description there I explain how it works.
In essence it does the following:
title,status,productandcomponentvalues.product: component(concatenated) stringdialog.During the procedure, you may open the Web Console (Ctrl+Shift+K) for progression log.
So, what it does (related to the problem I face) is:
getUniquefunctionretrieveValuesfunction for eachuniqueURL (gets the target HTML page viaGM_xmlhttprequestand extracts the relevant values)filterBugsfunction on each theuniquebug entriesi.e. it's this code:
The problem is that the resulting list is always empty.
It's related to the
GM_xmlhttprequestrequest(s) that's done inside theretrieveValuesfunction.I have put several logging entries in the script (as you may see in Web Console while it's running)
and it reveals that the
filterBugsfunction is called before allGM_xmlhttprequest(i.e. allretrieveValuescalls) are fully completed,(though I have set the
GM_xmlhttprequestrequest(s) to be done **synchronously)and so, all filtering is done on "empty values",
so all bugs are wrongly filtered out.
Could you help me with this, please?