Skip to content

Instantly share code, notes, and snippets.

@serdarcevher
Created June 30, 2020 17:53
Show Gist options
  • Save serdarcevher/73bc07baa9263ce0a2cd9516ea5d1e76 to your computer and use it in GitHub Desktop.
Save serdarcevher/73bc07baa9263ce0a2cd9516ea5d1e76 to your computer and use it in GitHub Desktop.
Another example to show using async/await
<script>
let randomNumber = Math.floor(Math.random() * 3) + 1;
function secondMessage() {
return new Promise(function(resolve) {
setTimeout(function() {
console.log('İkinci mesaj için ' + randomNumber + ' saniye bekledik');
resolve();
}, randomNumber * 1000);
});
}
async function printMessages() {
console.log('Birinci mesaj');
await secondMessage();
console.log('Üçüncü mesaj');
}
printMessages();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment