JSFiddle - React, Tailwind, and code Playground

by mattoconnell408

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.js"></script>

JavaScript

const returnedPromise1 = () => new Promise(resolve => {
  setTimeout(
    () => resolve('1'),
    3000
  );
});

const returnedPromise2 = () => new Promise(resolve => {
  setTimeout(
    () => resolve('2'),
    2000
  );
});

async function a() {
  const returnVal = await returnedPromise1();
  const returnVal2 = await returnedPromise2();
  // this takes 5 seconds
  console.log('a', returnVal, returnVal2);
};

async function b() {
  const [a, b] = await Promise.all([returnedPromise1(), returnedPromise2()]);
  // this takes 3 seconds
  console.log('b',  a, b);
};

a()
b()