Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Promise<number>
var promisedNumber = new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill(10) }, 500)
})
// Promise<string>
var promisedString = new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill(10) }, 1000)
})
console.log('start')
const AsyncPipeline = () => {
promisedNumber.then(
// using arrow functions to "save" some visual space
(value) => {
console.log('number: ', value)
promisedString.then(
(value) => { console.log('string:', value) },
(err) => { console.log('error:', err.message) }
)
},
(err) => { console.log('error: ', err.message) }
)
}
console.log('finish')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment