This file contains hidden or 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), (c -> d)) -> Promise<b | d> | |
// then :: ((a -> Promise b), (c -> Promise d)) -> Promise<b | d> |
This file contains hidden or 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
// Now this a thunk. | |
// Yeah, computer science b*tch! | |
// 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) | |
}) |
This file contains hidden or 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
// 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') |
This file contains hidden or 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
// Promise<number> | |
var promisedNumber = new Promise(function (fulfill, reject) { | |
setTimeout(() => { fulfill(10) }, 1000) | |
}); | |
// Promise<string> | |
var promisedString = new Promise(function (fulfill, reject) { | |
setTimeout(() => { fulfill('hello') }, 500) | |
}) |
This file contains hidden or 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
// Promise<number> | |
var promisedNumber = new Promise(function (fulfill, reject) { | |
setTimeout(() => { fulfill(10) }, 1000) | |
}); | |
// Promise<string> | |
var promisedString = new Promise(function (fulfill, reject) { | |
setTimeout(() => { fulfill('hello') }, 500) | |
}) |
This file contains hidden or 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
// Promise<number> | |
var promisedNumber = new Promise(function asyncUnitOfWork(fulfill, reject) { | |
throw new Error('Could not produce number (throw)') | |
}); | |
console.log('start') | |
promisedNumber.then( | |
function onFulfilled(value) { |
This file contains hidden or 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
// Promise<number> | |
var promisedNumber = new Promise(function asyncUnitOfWork(fulfill, reject) { | |
setTimeout(function () { | |
reject(new Error('Could not produce number')) | |
}, 1000) | |
}); | |
console.log('start') | |
This file contains hidden or 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
// Promise<number> | |
var promisedNumber = new Promise(function asyncUnitOfWork(fulfill, reject) { | |
setTimeout(function () { | |
fulfill(10) | |
}, 1000) | |
}); | |
console.log('start') | |
promisedNumber.then( |
This file contains hidden or 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
// Promise<number> | |
var promisedNumber = new Promise(function asyncUnitOfWork(fulfill, reject) { | |
setTimeout(function () { | |
fulfill(10) | |
}, 1000) | |
}); | |
console.log('start') | |
console.log('value: ', promisedNumber) // Promise {<pending>} | |
console.log('finish') |
This file contains hidden or 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
const { compose, curry } = require('lodash/fp') | |
// Success :: a -> Success a | |
const Success = value => ({ | |
type: 'success', | |
value | |
}) | |
Success.is = obj => obj.type === 'success' |