Created
November 24, 2014 04:59
-
-
Save victorvhpg/779b31eabfcb55f7a45d to your computer and use it in GitHub Desktop.
Comparação callbacks / Promise
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
//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