Sleep function in ES6

Function JavaScript 1 revisions 380 2 years ago 2 years ago
function sleep(ms) {
	return new Promise(resolve => setTimeout(resolve, ms));

Use like:

await sleep(500); // Sleeps for 500ms

Now for the most important part, do not do this on the main execution pipe, this will freeze the whole browser tab and won't be nice. Make sure you're using this in a promise or something so it doesn't freeze rendering.