Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Forever – listen to emit
/*jslint white: true, devel: true, debug: true, onevar: true,
node: true, undef: true, nomen: true, regexp: false,
plusplus: false, bitwise: true, unparam: false, es5: true,
newcap: true, on: true, strict: true */
(function (global, undefined) {
"use strict";
require.paths = [ '/Users/Andreas/.node_modules', '/usr/local/lib/node_modules' ];
console.log("nodejs module path: ", require.paths);
console.log("");
//get the forever module
var forever = require("forever"),
emitter = "/Users/Andreas/Sites/WebNodes/interface/emitter.js",
child;
//extend
forever.Forever.prototype["__proto__"]["__old__emit"] = forever.Forever.prototype["__proto__"].emit;
forever.Forever.prototype["__proto__"].emit = function () {
var eventname = arguments[0],
list;
if (eventname != "newListener") {
list = forever.list(false) || [];
console.log(":: emiting: " + arguments[0]);
console.log(":: processors: ", list.length);
}
return this["__old__emit"].apply(this, arguments);
};
console.log("");
console.log("get the list:");
console.log("forever.list(true)", forever.list(true));
console.log("forever.list(false).length", (forever.list(false) || []).length);
console.log("");
console.log("Start emitter.js");
child = new (forever.Forever)(emitter);
child.on("start", function () {
console.log("> emitter.js emits start");
console.log("> > forever.list(true)", forever.list(true));
console.log("> > forever.list(false).length", (forever.list(false) || []).length);
console.log("> stop emmiter.js");
child.stop();
});
child.on("stop", function () {
console.log("> emitter.js emits stop");
console.log("> > forever.list(true)", forever.list(true));
console.log("> > forever.list(false).length", (forever.list(false) || []).length);
});
child.start();
})(global);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.