JSFiddle - React, Tailwind, and code Playground

by evgkch

JavaScript

const fetchSomthing = ()=>new Promise(res=>{
	setTimeout(()=>{
  	res(Math.floor(Math.random() * 10));
  }, Math.floor(Math.random() * 5000))
});

const createQueue = promisesList=>{
	const firstPromise = promisesList[0];
  if (promisesList.length > 0)
  {
  	firstPromise.then(res=>{
    	console.log(res);
    	createQueue(promisesList.splice(1));
    });
  }
  else
  	return firstPromise;
};

createQueue([
	fetchSomthing(),
  fetchSomthing(),
  fetchSomthing(),
])