Have to take multiple SOAP requests and need to take back all the returns together.
What I do now is:
for (let this_target of list_of_target)
{
const req = http.request(conn, (res) => {
let data='';
res.on('data', (chunk) =>
{
data += chunk;
});
res.on('end', () =>
{
... do some stuff with the result of the SOAP request ...
my_external_array.concat (myData);
});
});
var om_req={
'CT_Get' : {
...some extra stuff...
'target': this_target
...some extra stuff...
}
};
var builder=new xml2js.Builder();
var om_req_xml=builder.buildObject(om_req);
req.write(om_req_xml);
req.end();
}
ok
I know that I can't retrive the data outside this loop because the callback.
Curiously (or not), if I add a console.log(my_external_array)
just after my_external_array.concat (myData);
, the script shows the adding of the items after each processing... However if I put the same console.log
outside the callback (anywhere) I don't have any return... :(
Which would be the best way to process all those request, join the results into an array and pass it to some another function. I need all the values from this requests to summarize them and save the summarized result into a database
Sorry being not more detailed about what I'm doing...