How to work with a nondeterministic number of jQuery promises?

jquery, jquery-deferred, promise

Solution

push all the promises into an array and use:

$.when.apply(null, promiseArray).done(function() {....

Problem

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.

Original source