Thank you Ian, for pointing me towards promises. Since I already make use of jQuery, I decided to use their implementation. The image()
function for loading returns a promise now and this is what I ended up with.
// create a new document
var doc = new jsPDF();
// load all images and give me the promises
var promises = urls.map(image);
// handle individual results
promises.map(function(promise) {
promise.done(function(e) {
// don't care about the coordinates,
// I simplified this for this example
doc.addImage(e.data, 'jpeg', 0, 0, 10, 10);
}).fail(console.log);
});
// handle overall readiness
$.when.apply($, promises).done(function() {
// output the resulting document
doc.output('dataurl');
}, console.log);