JSFiddle - React, Tailwind, and code Playground

JavaScript

function sleep(time) {
	return new Promise((resolve, reject) => {
		setTimeout(resolve, time);
	})
}

async function asyncExample() {
	let f = 0;
	let i = setInterval(() => {
		f = Math.random();
	}, 50);
	console.log(f);
	await sleep(1000);
	console.log(f);
	clearInterval(i);
}

asyncExample();