Skip to content

Instantly share code, notes, and snippets.

@mishelashala
Last active July 27, 2020 14:12
Show Gist options
  • Save mishelashala/d12336b2383efac1d02a51e864541654 to your computer and use it in GitHub Desktop.
Save mishelashala/d12336b2383efac1d02a51e864541654 to your computer and use it in GitHub Desktop.
// PromisedNumber :: () -> Promise<error>
const PromisedNumber = () => new Promise(function (fulfill, reject) {
setTimeout(() => { reject(new Error('could not produce number')) }, 500)
})
// PromisedString :: () -> Promise<string>
const PromisedString = () => new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill(10) }, 1000)
})
console.log('start')
const AsyncPipeline = () => {
// we don't actually need these two variables
const promisedNumber = PromisedNumber()
const promisedString = PromisedString()
promisedNumber.then((value) => {
console.log('number: ', value)
return promisedString
})
.then((value) => { console.log('string:', value) })
.catch((err) => { console.log('error:', err.message) })
}
AsyncPipeline()
console.log('finish')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment