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
// resolve :: a -> Promise a | |
// reject :: a -> Promise a | |
// of :: a -> AsyncMonad a | |
// then :: (a -> b) -> Promise b | |
// map :: (a -> b) -> AsyncMonad b | |
// then :: (a -> Promise b) -> Promise b | |
// flatMap :: (a -> AsyncMonad b) -> AsyncMonad b |
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
// resolve :: a -> Promise<a> | |
// reject :: a -> Promise<a> |
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
// of :: (a) -> AsyncMonad a |
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
// flatMap :: (a -> AsyncMonad b) -> AsyncMonad b |
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
// map :: (a -> b) -> AsyncMonad b |
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
// then :: (a -> b) -> Promise b | |
// then :: (a -> Promise b) -> Promise b |
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
// fulfilled promise | |
const promisedNumber = Promise.resolve(12) | |
promisedNumber.then(value => console.log('number:', value)) | |
// rejected promise | |
const rejectedString = Promise.reject(new Error('could not produce string')) | |
rejectedString.catch(err => console.log('error:', err.message)) |
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<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') |
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<Error> | |
const PromisedNumber = () => new Promise(function (fulfill, reject) { | |
setTimeout(() => { reject(new Error('could not produce number')) }, 500) | |
}) |
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') |
NewerOlder