Do something just before a callback is executed
Do something as an aside to a callback.
Potentially useful for logging calls to particular callbacks. Maybe other stuff too.
var interject = require'interject';varconsole.logmsg;if cb cbnull msg;;varconsole.log'You said: ' + msg +'\n';;varconsole.log'On ' + + ', somebody said: ' + msg;;say'Interject me please.' afterSay;// Output:// Interject me please.// You said: Interject me please.var sayLogged = interjectsay logMessage;sayLogged'Interject me please.' afterSay;// Output:// Interject me please.// On Fri Mar 28 2014 18:20:41 GMT-0400 (EDT), somebody said: Interject me please.// You said: Interject me please.
interjected/* do something */;
Assuming the implementation of
func accepts a callback (as it's last parameter), the function returned by
interject will invoke both the
interjection (as an aside) and the
callback provided to
interjected at the
func implementation would have executed it's callback. It's important to note that the
interjection will be
called just before the
callback, but it is not gauranteed to complete before
callback is called.
interjection receives the same
arguments as the
Also of note - when nesting interjections, the interjections will be called in the order they are defined before the final
var cb ;var /* I am called 1st */ ;var interjected = interjectoriginal interjection1;var /* I am called 2nd */ ;var interjected = interjectinterjected interjection2;interjected;
npm install interject