I'm working on simple extension for Gnome DE and have some trouble wrapping my head around asynchronous Soup calls and the event loop.
Here's what I have:
_httpSession = new Soup.Session();
let token = 'sometoken'
let url = 'someurl';
let _allData = [];
let elements = [1,2];
for (let el of elements) {
let message = Soup.form_request_new_from_hash('GET', url + el, { access_token: token });
_httpSession.queue_message(message, () => {
if (message.status_code != Soup.KnownStatusCode.OK) {
_error(message.status_code.toString());
}
try {
message = JSON.parse(message.response_body.data).items;
} catch (e) {
_error(e.toString());
}
_allData = _allData.concat([el, message]);
});
}
Given the asynchronous calls in a for loop above, how to make sure that _allData.concat() has been executed for all iterations? I want to print out the _allData variable, but only when concatenations for each el were executed.