Skip to content

Instantly share code, notes, and snippets.

@davidcostadev
Created July 1, 2017 19:14
Show Gist options
  • Save davidcostadev/e8d2c86c3ee9d7a738e75b5a9c655b71 to your computer and use it in GitHub Desktop.
Save davidcostadev/e8d2c86c3ee9d7a738e75b5a9c655b71 to your computer and use it in GitHub Desktop.
Estruturando promises
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