while (data.length) {
var slice = data.splice(0, 10);
var ds = [];
slice.forEach(function (v) {
ds.push($.ajax({
'url': 'index.php?action=getzip'
'type': 'POST',
'data': {
'country': v.country,
'city': v.city,
},
'dataType': 'JSON',
}));
});
$.when.apply(null, ds).then(function() {
// recursion may be here or...?
});
}
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const chunks = 3;
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let promise = Promise.resolve();
for (let i = 0; i < data.length; i += chunks) {
const slice = data.slice(i, i + chunks);
promise = promise.then(() => Promise.all(
slice.map(() => console.log(i))
));
}
promise.then(() => console.log('all done'));