thenction
v1.0.4
Published
thenction is abbreviation of thenable function
Downloads
4
Maintainers
Readme
thenction
thenction is an abbreviation of thenable function.
Install
$ npm i -S thenction
Usage
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
API
require('thenction')(Promise)
Returns a thenction(baseFn)
function.
Promise
Type: Fucntion
Your favorite Promise implementation
thenction(baseFn)
Returns a thenable function.
baseFn
Type: Function
Base function to be composed by then
and catch
.
thenableFunction.then(onFulfilled, [onRejected])
onFulfilled
Type: Function
onRejected
Type: Function
thenableFunction.catch(onRejected)
onRejected
Type: Function
License
MIT and :sushi: © TSUYUSATO "MakeNowJust" Kitsune <[email protected]> 2016