Say I have a very long list where each element requires an asynchronous call to fetch. I would like to write an API on top of that list so that a consumer can simply call \"
You can't have such syntax because it would just go into infinite busy loop.
There is a common promise idiom to do this:
var array = [process1AndFetch2, ...]
array.reduce(function(a, b) {
return a.then(process).then(b);
}, array.shift()()).then(function(){
//All processed
});
Assumes jQuery 1.8+