Skip to content

Instantly share code, notes, and snippets.

@WandersonAlves
Created June 30, 2018 23:02
Show Gist options
  • Save WandersonAlves/d9dccc5634d4159f20b3d97a1e49b14d to your computer and use it in GitHub Desktop.
Save WandersonAlves/d9dccc5634d4159f20b3d97a1e49b14d to your computer and use it in GitHub Desktop.
#1 async/await/then leasson
( async () => {
const pegarAsyncPromise = (id) => {
return new Promise((resolve, reject) => {
if (id % 2 === 0) {
resolve(true);
}
else {
reject(false);
}
});
}
let resultadoPromise;
pegarAsyncPromise(1).then(resolve => {
resultadoPromise = resolve;
console.log('then', resultadoPromise);
}).catch(reject => {
resultadoPromise = reject;
console.log('then', resultadoPromise)
})
try {
const resultadoPromiseAsync = await pegarAsyncPromise(1);
console.log('async', resultadoPromiseAsync)
}
catch (result) {
console.log('async', result);
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment