0.1.1 • Published 12 years ago
bbq v0.1.1
bbq
AOP with Promises
usage example
var bbq = require('bbq')
function foo(){
// return a promise
}
bbq(foo, {
before: function () {
this.start = Date.now()
},
after: function () {
this.end = Date.now()
this.elapsed = this.end - this.start
console.log('promise resolved in ' + this.elapsed + 'ms')
}
})
.then(function (resolvedValOfFoo) {
// stuff
})api
bbq: (promiser: () => Promise, advice?: {before: Function, after: Function}) => Promise
before and after are AOP advice, functions which can modify the control flow of the promiser.
- Advice can modify the return value by returning other than undefined or a Promise of undefined.
- Advice is called in the
thiscontext of astateobject, which can be used to keep track of state between before and after advice for thatpromiserinvocation. - If
beforeadvice returns a value, it will short-circuit thepromiserfrom being called. afteradvice hasthis.valset to the return value of thepromiser. Ifafterreturns a value other than undefined or a Promise of undefined, it will be the ultimate resolved value; otherwisethis.valwill be used.
installation
$ npm install bbqrunning the tests
From package root:
$ npm install
$ npm testcontributors
- jden jason@denizac.org
license
MIT. (c) MMXIII jden jason@denizac.org. See LICENSE.md