Bootstrap

Promise并发控制,即限制异步操作的并发个数并尽可能快的完成全部

假设有如下七个请求

const delay = s => new Promise(r => setTimeout(r, s));

const fn1 = async () => {
   
  console.log('fn1 fetching');
  await delay(1000);
  console.log('fn1 fetch end');
  return 'fn1';
};

const fn2 = async () => {
   
  console.log('fn2 fetching');
  await delay(2000);
  console.log('fn2 fetch end');
  return 'fn2';
};

const fn3 = async () => {
   
  console.log('fn3 fetching');
  await delay(3000);
  console.log('fn3 fetch end');
  
;