Created
May 29, 2019 04:57
-
-
Save dekisr/4490897147fd9b65c168f548b46bdc35 to your computer and use it in GitHub Desktop.
Exemplo para Daniel - Quiz Chaining Thens
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
// Testes para o Quiz Chaining Thens | |
const data = { | |
name: 'Daniel', | |
age: 30, | |
studying: [ "JavaScript", "React" ] | |
} | |
const promiseTest = () => { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(data) | |
}, 500) | |
}) | |
} | |
async function asyncTest() { | |
const response = await promiseTest() | |
return response | |
} | |
function nothing() {} | |
asyncTest() | |
.then(data => { | |
coconsole.log(data.name) // erro forçado para entrar no catch abaixo | |
return data.studying | |
}) | |
.then(undefined, (error) => { | |
coconsole.log('1:', error) // erro forçado para entrar no catch abaixo | |
return nothing() | |
}) | |
.catch((error) => { | |
console.log('2:', error) // ainda iria imprimir esta linha | |
return coconsole.log(42) // erro forçado para acabar aqui | |
}) | |
.then((resp) => { | |
console.log('3:', resp) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment