Skip to content

Instantly share code, notes, and snippets.

@victorvhpg
Created November 24, 2014 04:59
Show Gist options
  • Save victorvhpg/779b31eabfcb55f7a45d to your computer and use it in GitHub Desktop.
Save victorvhpg/779b31eabfcb55f7a45d to your computer and use it in GitHub Desktop.
Comparação callbacks / Promise
//callbacks dentro de callbacks
algumaCoisa1(function(resposta1) {
//...
algumaCoisa2(function(resposta2) {
//...
algumaCoisa3(function(resposta3) {
//...
acaoFinal(resposta3);
});
});
});
//usando Promise encadeadas
//supondo que tudo retorne uma Promise entao:
algumaCoisa1().then(function(resposta1) {
return algumaCoisa2();
}).then(function(resposta2) {
return algumaCoisa3();
}).then(function(resposta3) {
acaoFinal(resposta3);
}).catch(function(erro){
//caso algum erro ocorra em qualquer uma
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment