process.addAsyncListener polyfill
This is an implementation of Trevor Norris's
process.{addAsyncListener,removeAsyncListener} API for adding behavior to async
calls. You can see his implementation (currently a work in progress) on
Node.js core pull request #5011.
This polyfill / shim is intended for use in versions of Node prior to whatever
version of Node in which Trevor's changes finally land (anticipated at the time of
this writing as 0.11.7).
Here's his documentation of the intended API, which will probably get cleaned up
here later:
function Domain() { }
function onAsync(context) {
return new Domain();
}
var callbackObject = {
before: function asyncBefore(domain) {
},
after: function asyncAfter(domain) {
},
error: function asyncError(err, domain) {
},
done: function asyncDone(domain) {
}
};
var key = process.addAsyncListener(onAsync, callbackObject);
process.removeAsyncListener(key);