-
-
Save michaelfdias/95162f4fb7b4ff5a0a29592a92049390 to your computer and use it in GitHub Desktop.
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
// https://medium.com/balta-io/melhorando-suas-promessas-no-javascript-28f81272f5cf | |
main(); | |
function main() { | |
funcaoUm() | |
.then(funcaoDois) | |
.then(funcaoTres) | |
.then(funcaoQuatro) | |
.then(funcaoCinco) | |
.then(funcaoSeis); | |
} | |
function funcaoUm() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('1'); | |
resolve(); | |
}, 1234); | |
}); | |
} | |
function funcaoDois() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('2'); | |
resolve(); | |
}, 100); | |
}); | |
} | |
function funcaoTres() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('3'); | |
resolve(); | |
}, 1000); | |
}); | |
} | |
function funcaoQuatro() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('4'); | |
resolve(); | |
}, 870); | |
}); | |
} | |
function funcaoCinco() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('5'); | |
resolve(); | |
}, 330); | |
}); | |
} | |
function funcaoSeis() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('6'); | |
resolve(); | |
}, 420); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Desculpa por responder antes do Michael, é que eu também li o artigo e gostaria de ajudar.
No caso desse exemplo usando
async
/await
acredito que ficaria dessa forma:Observação:
main
sempre deve ser precedida deasync
.await
.