function fn(id){
return new Promise((resolve, reject) => {
let data = fs.readFileSync('file' + id + '.txt', 'utf-8');
resolve(data);
});
}
for(let i = 0; i < 1000; i++){
fn(i);
}
function fn(id){
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(id);
resolve(id);
}, Math.random() * 1000);
});
}
for(let i = 0; i < 100; i++){
fn(i);
}