1
I need to do the asynchronous processing of data series (sending data to a REST server) and, only at the end of all requests, I need to perform another function.
How can I control this flow if each request is asynchronous?
What I need is something like this:
for (var i=0; l<objetos.length; i++){
var o=objetos[i];
Enviar($q, o).then(function(){})
}
//ao término de todas as requisições acima, disparar um novo evento...
If you have all the data on
objetos, why not send them at once? Don’t overload your page with multiple requests. It’s not good practice.– DontVoteMeDown
If it is ajax there is a configuration called: async, put the async value: false, and then yes you have several functions in case of success and fail.
– Wilson -
@Dontvotemedown I am sending a file and the server only accepts one file at a time.
– NilsonUehara
@Wilson is sending the file with the
cordovaFileTransfer.upload()– NilsonUehara
@Wilson- It is better to avoid this at all costs, not only by crashing the user interface, but also because will no longer be supported by browsers.
– bfavaretto