JSFiddle - React, Tailwind, and code Playground

by kouty79

JavaScript

function timeout() {
	return new Promise((resolve)=>{
  	setTimeout(resolve, Math.random()*1000);
  });
}

const NUM = 1000;
let count = 0;
const promisses = [];
for(let i=0; i<NUM; i++) {
	promisses.push(timeout().then(()=>count++));
}

Promise.all(promisses).then(()=>{
	console.log(count);
  if(count !== NUM) alert('error');
});