JSFiddle - React, Tailwind, and code Playground

by Bart Kalisz

JavaScript

const x = () => new Promise((res, rej) => {
	setTimeout(() => res("x"), 1000);
});
const y = () => new Promise((res, rej) => {
	setTimeout(() => res("y"), 2000);
});
const z = () => new Promise((res, rej) => {
	setTimeout(() => res("z"), 3000);
});

const start = Date.now();

Promise.all([x(), y(), z()]).then((xyz) => {
	console.log(xyz, `${(Date.now() - start) / 1000}s`);
});

const xyz = async function() {
	await x();
	await y();
	await z();
	console.log("await", `${(Date.now() - start) / 1000}s`);
};

xyz();