Skip to content

Commit

Permalink
Merge pull request #41 from baalexander/set_max_listener
Browse files Browse the repository at this point in the history
Sets unlimited number of event listeners.
  • Loading branch information
rctoris committed May 3, 2013
2 parents 02d6658 + 577b663 commit 5eb0108
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions build/roslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ ROSLIB.Ros = function(options) {
this.socket = null;
this.idCounter = 0;

// Sets unlimited event listeners.
this.setMaxListeners(0);

// begin by checking if a URL was given
if (url) {
this.connect(url);
Expand Down
2 changes: 1 addition & 1 deletion build/roslib.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/core/Ros.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ ROSLIB.Ros = function(options) {
this.socket = null;
this.idCounter = 0;

// Sets unlimited event listeners.
this.setMaxListeners(0);

// begin by checking if a URL was given
if (url) {
this.connect(url);
Expand Down
31 changes: 31 additions & 0 deletions test/ros.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var expect = chai.expect;

describe('ROS', function() {

describe('callOnConnection', function() {
it('should accept more than EventEmitter2\'s default listeners', function() {
// By default, EventEmitter2 only accepts 10 listeners. When more than
// the default, a 'warn' property is set on the listener. The firt part
// of this test proves the 'warn' property will be set with default
// EventEmitter2 settings.
var callCount = 50;
var eventEmitter = new EventEmitter2();
for (var i = 0; i < callCount; i++) {
eventEmitter.on('foo', function() { });
}
expect(eventEmitter._events['foo']).to.have.length(callCount);
expect(eventEmitter._events['foo']).to.have.property('warned');

// The next part of this test shows that the 'warn' property is not set
// for Ros, even with the same number of listeners as above.
var ros = new ROSLIB.Ros();
for (var i = 0; i < callCount; i++) {
ros.callOnConnection({});
}
expect(ros._events['connection']).to.have.length(callCount);
expect(ros._events['connection']).to.not.have.property('warned');
});
});

});

0 comments on commit 5eb0108

Please sign in to comment.