Skip to content

Instantly share code, notes, and snippets.

@jgranados4
Last active Jul 27, 2022
Embed
What would you like to do?
Promise y Async
const datos = [
{
id: 1,
Nombre: "Juan",
},
{
id: 2,
Nombre: "Gustavo",
},
{
id: 3,
Nombre: "Alex",
},
];
//Promise
const getDatos = () => {
return new Promise((resolve, reject) => {
if (datos.length === 0) {
reject(new error("no existe datos"));
}
setTimeout(() => {
resolve(datos);
}, 2000);
});
};
//ASYNC Y AWAIT
async function inicio() {
try {
const datosq = await getDatos();
console.log(datosq);
} catch (error) {
console.log(error.message);
}
}
inicio();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment