Created
May 5, 2019 01:22
-
-
Save dekisr/ef08ffa839a407a52494f08009ae8265 to your computer and use it in GitHub Desktop.
Exemplo para Daniel
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
function condicao() { | |
return Math.floor(Math.random() * (4-1)) === 1 | |
} | |
function atraso(ms) { | |
return new Promise((resolve, reject) => { | |
setTimeout(function() { | |
condicao() ? resolve('Foi que foi') : reject('Deu ruim') | |
},ms) | |
}) | |
} | |
atraso(2000) | |
.then(resposta => console.log(`A resposta da promise é: ${resposta}`)) | |
.catch(erro => console.log(`O erro foi: ${erro}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment