Created
June 30, 2020 17:53
-
-
Save serdarcevher/73bc07baa9263ce0a2cd9516ea5d1e76 to your computer and use it in GitHub Desktop.
Another example to show using async/await
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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