Last active
July 20, 2017 16:44
-
-
Save gaverdugo/fa1980df57ff6adead32d918df5e67f2 to your computer and use it in GitHub Desktop.
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
// Como usar async await 😎 | |
// Defines la función que lo encierra como async. | |
// Cualquier funcion que regrese una promise va a tener un await antes. | |
let asyncAwait = async () => { | |
await fetch('algo'); | |
}; | |
// Aun tenemos que manejar errores. | |
// Hay dos formas de cachar errores. | |
// Usar try catch. | |
let asyncAwait = async () => { | |
try { | |
await fetch('algo'); | |
} catch(err) { | |
throw Error(err); | |
console.log('No se pudo 😭'); | |
} | |
}; | |
// O como todas las funcionas async regresan una promesa | |
// se puede hacer encadenar un catch despues. | |
asyncAwait().catch(err => { | |
console.log('Ay, se rompio algo 😖'); | |
}); | |
// O se puede escribir codigo que no produzca errores, | |
// Pero no existe lenguaje de programación que haga eso todavia. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment