Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work with a nondeterministic number of jQuery promises?

If I have a nondeterministic number of promises being generated how do I handle them as a group to ensure the all of the promises in the group have been resolved before I move forward in my code?

I though about using jQuery.when but it looks like it requires a deterministic number of promises passed as arguments. I thought I would be able to pass an array of promises for processing but based upon the docs I think it will evaluate this array as a single resolved promise.

like image 558
bcardarella Avatar asked Oct 21 '22 16:10

bcardarella


1 Answers

push all the promises into an array and use:

$.when.apply(null, promiseArray).done(function() {....
like image 146
charlietfl Avatar answered Nov 01 '22 15:11

charlietfl