Skip to content
npm module: AOP with Promises
JavaScript
Latest commit 30fd48e Dec 5, 2013 @jden upgrade to bluebird
Failed to load latest commit information.
test upgrade to bluebird Dec 5, 2013
.gitignore initialize bbq Jul 24, 2013
LICENSE.md initialize bbq Jul 24, 2013
README.md impl Jul 24, 2013
index.js upgrade to bluebird Dec 6, 2013
package.json upgrade to bluebird Dec 6, 2013

README.md

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 this context of a state object, which can be used to keep track of state between before and after advice for that promiser invocation.
  • If before advice returns a value, it will short-circuit the promiser from being called.
  • after advice has this.val set to the return value of the promiser. If after returns a value other than undefined or a Promise of undefined, it will be the ultimate resolved value; otherwise this.val will be used.

installation

$ npm install bbq

running the tests

From package root:

$ npm install
$ npm test

contributors

license

MIT. (c) MMXIII jden jason@denizac.org. See LICENSE.md

Something went wrong with that request. Please try again.