Permalink
Browse files

suppress '(node) warning: possible EventEmitter memory leak detected.'

  • Loading branch information...
1 parent 1886aab commit 6afe92b9d08c6f62ced3a36186d63e2d66b06f74 Paul Baumgart committed Jun 20, 2012
Showing with 28 additions and 1 deletion.
  1. +3 −0 lib/bundle.js
  2. +24 −0 lib/suppress.js
  3. +1 −1 package.json
View
@@ -4,6 +4,7 @@ var path = require('path');
var _ = require('underscore');
var template = require('./template');
var Module = require('./module');
+var suppress = require('./suppress');
function Bundle(options) {
this._options = options;
@@ -97,6 +98,7 @@ Bundle.prototype = {
_watchFile: function(filename) {
var itself = this;
if (!this._watchedFiles[filename]) {
+ suppress.suppressEventEmitterWarning();
fs.watchFile(filename, {
persistent: false,
interval: 10
@@ -111,6 +113,7 @@ Bundle.prototype = {
}
});
});
+ suppress.allowEventEmitterWarning();
this._watchedFiles[filename] = true;
}
},
View
@@ -0,0 +1,24 @@
+// This file implements a workaround for the fact that Node does not expose
+// a way to call setMaxListeners() for StatWatcher objects (the objects that
+// handle file watching).
+
+var consoleTrace = console.trace;
+var consoleError = console.error;
+
+function suppressEventEmitterWarning() {
+ console.trace = function() {};
+ console.error = function(msg) {
+ if (!/warning: possible EventEmitter memory leak detected/.test(msg)) {
+ consoleError.apply(this, arguments);
+ }
+ };
+}
+
+function allowEventEmitterWarning() {
+ console.trace = consoleTrace;
+ console.error = consoleError;
+}
+
+exports.suppressEventEmitterWarning = suppressEventEmitterWarning;
+exports.allowEventEmitterWarning = allowEventEmitterWarning;
+
View
@@ -3,7 +3,7 @@
"name": "jsbundle",
"description": "Simple, clean, and automatic bundling of your Node modules and packages for use in the browser.",
"keywords": "browser require bundle module package static-analysis",
- "version": "0.10.1",
+ "version": "0.10.2",
"repository": {
"type": "git",
"url": "git://github.com/proxv/jsbundle.git"

0 comments on commit 6afe92b

Please sign in to comment.