Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sets unlimited number of event listeners. #41

Merged
merged 1 commit into from
May 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});

});