Skip to content

Commit

Permalink
Adding description for timeout constructor option and changing spaces…
Browse files Browse the repository at this point in the history
… to tabs
  • Loading branch information
JvrBaena committed Oct 9, 2015
1 parent baaf8a8 commit 5cfaeca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -9,6 +9,12 @@ Currenly, this module only supports JSON activity stream format, so you must ena
# Gnip.Stream
This class is an EventEmitter and allows you to connect to the stream and start receiving data.

## Constructor options

#### options.timeout
As requested in the Gnip docs (http://support.gnip.com/apis/powertrack/api_reference.html), this option in the constructor allows us to set a read timeout in the client. The recommended a value is >=30 seconds, so the constructor will throw an error if a smaller timeout is provided. The default value for this option is 35 seconds.


## API methods

#### stream.start()
Expand Down
16 changes: 8 additions & 8 deletions lib/index.js
Expand Up @@ -61,7 +61,7 @@ GnipStream.prototype.start = function() {
if (self.options.debug) util.log('Starting stream...');

if (!self.options.url) throw new Error('Invalid end point specified!');
if (self.options.timeout && self.options.timeout <= 30000) throw new Error('Timeout must be beyond 30s');
if (self.options.timeout && self.options.timeout <= 30000) throw new Error('Timeout must be beyond 30s');

if (self._req) self.end();

Expand Down Expand Up @@ -113,13 +113,13 @@ GnipStream.prototype.start = function() {
}
});

self._req.on('socket', function(socket) {
socket.setTimeout(self.options.timeout || 35000);
socket.on('timeout', function() {
self.emit('error', new Error('Connection Timeout'));
self.end();
})
});
self._req.on('socket', function(socket) {
socket.setTimeout(self.options.timeout || 35000);
socket.on('timeout', function() {
self.emit('error', new Error('Connection Timeout'));
self.end();
})
});

self._req.on('error', function(err) {
self.emit('error', err);
Expand Down

0 comments on commit 5cfaeca

Please sign in to comment.