Created
March 1, 2019 19:26
-
-
Save edujr1/0bb831e68f3deab4f3fef0777e9a94de to your computer and use it in GitHub Desktop.
javascript assíncrono com Async/Await
This file contains hidden or 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
const sleep = m => new Promise(r => setTimeout(r, m)) | |
const funcaoComCallbackAsync = async (callback) => { | |
await sleep(1000) | |
console.log("3- Antes do callback"); | |
if (callback) {await callback()} | |
await sleep(1000) | |
console.log("5- Depois do callback"); | |
} | |
const funcaoInicialAsync = async () => { | |
console.log("1- INICIO SCRIPT"); | |
await sleep(1000) | |
console.log("2- Chama funcao com Callback") | |
await funcaoComCallbackAsync(async()=>{ | |
await sleep(1000) | |
console.log("4- Dentro do Callback") | |
}) | |
await sleep(1000) | |
console.log("6- Depois da funcao com Callback") | |
await sleep(1000) | |
console.log("7- FIM SCRIPT"); | |
} | |
funcaoInicialAsync() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment