thenction is an abbreviation of thenable function.
$ npm i -S thenction
const thenction = require('thenction')(Promise)
// or: const thenction = require('thenction')(require('your-favorite-promise-lib'))
const twiceLog = thenction(value => value * 2).then(value => (console.log(value), value))
Promise.resolve(2).then(twiceLog)
//=> 4
twiceLog(2).then(value => console.log(value))
//=> 4
//=> 4
Promise.resolve(2).then(twiceLog.then(twiceLog))
//=> 4
//=> 8
const twiceLogSleep = twiceLog
.then(value => new Promise(resolve => setTimeout(resolve, 1000, value)))
Promise.resolve(2).then(twiceLogSleep).then(twiceLog)
//=> 4
// after 1s
//=> 8
const twiceLogError = twiceLog
.then(value => { throw new Error('wow') })
.catch(error => console.log(error))
Promise.resolve(2).then(twiceLogError)
//=> 4
//=> Error: wow
Returns a thenction(baseFn)
function.
Type: Fucntion
Your favorite Promise implementation
Returns a thenable function.
Type: Function
Base function to be composed by then
and catch
.
Type: Function
Type: Function
Type: Function
MIT and 🍣 © TSUYUSATO "MakeNowJust" Kitsune <make.just.on@gmail.com> 2016