javascript - Angular q.all instant vs delayed responses -
i have methodology question. using $q.all
capture multiple promises in single return, processing results single request.
ie: $q.all([promise1(),promise2(),promise3(),promise(4),promise5()])..then(function(response){ ...}
however, noticing different promises being returned @ different time frames. promises http calls third party sites. when particular promise delayed 8 seconds...or 14 seconds, final results of promises delayed same duration. weakest...rather 'slowest'...link syndrome.
what method can use call promises @ same time yet still allow results processed, , viewed user, come in? not wait on of them returned before processing them @ once?
as suggested in comments use them separately, if want call them @ same time , handle them in 1 promise, can use notify
-callback of promise. i've created extension $q
uses notify()
function resolve promises one:
app.run(function($q){ $q.each = function(promises){ var deferred = $q.defer(); promises.foreach(function(promise){ promise.then(function(data){ deferred.notify(data); }); }); return deferred.promise; }; });
this pretty naive implementation doesn't handle errors instance, gives idea of what's involved.
then you'd use this:
var promises = [promise1(),promise2(),promise3(),promise(4),promise5()]; $q.each(promises).then(null, null, function(data){ console.log(data); // called when each promise resolves. });
Comments
Post a Comment