Created
July 1, 2017 19:14
-
-
Save davidcostadev/e8d2c86c3ee9d7a738e75b5a9c655b71 to your computer and use it in GitHub Desktop.
Estruturando promises
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
function calcular() { | |
return new Promise((resolve, reject) => { | |
console.log('inicio...') | |
resolve() | |
}) | |
} | |
function um() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('+1') | |
resolve(1) | |
}, 1000) | |
}) | |
} | |
function dois(result) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('+2') | |
resolve(result + 2) | |
}, 1000) | |
}) | |
} | |
function igual(result) { | |
return new Promise((resolve, reject) => { | |
console.log('calculando....') | |
setTimeout(() => { | |
console.log('resultado='+ result) | |
resolve(true) | |
}, 1000) | |
}) | |
} | |
calcular() | |
.then(um) | |
.then(dois) | |
.then(igual) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment