function load(index){
return new Promise((res, rej) => {
setTimeout(() => {
console.log(index);
res();
}, 3000)
})
}
function promiseLimit(arr, limit, fn){
let index = 0;
function init(){
index++;
if(index <= arr.length){
fn(index).then(() => {
init()
})
}
}
for(let i = 0; i < limit; i++){
init()
}
}
promiseLimit([1,2,3,4,5,6,7,8,9], 3, load)