Last active
July 27, 2020 13:49
-
-
Save mishelashala/665f4fa5647d06f9ff1e2ce3b02dd6c4 to your computer and use it in GitHub Desktop.
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
// PromisedNumber :: () -> Promise<number> | |
const PromisedNumber = () => new Promise(function (fulfill, reject) { | |
setTimeout(() => { fulfill(10) }, 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 | |
}, | |
(err) => { console.log('error: ', err.message) } | |
) | |
.then( | |
(value) => { console.log('string:', value) }, | |
(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