Skip to content

Instantly share code, notes, and snippets.

@dxrcy
Created November 12, 2020 03:40
Show Gist options
  • Save dxrcy/6b440911453ae197aaf8b9c04ff2a3d3 to your computer and use it in GitHub Desktop.
Save dxrcy/6b440911453ae197aaf8b9c04ff2a3d3 to your computer and use it in GitHub Desktop.
Sleep function for async javascript
function sleep(time) {
return new Promise(resolve => {
setTimeout(resolve, time * 1000);
});
}
(async()=>{
console.log("Start");
await sleep(1);
console.log("1 second later");
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment