Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

Commit

Permalink
add read-timeout to connection execute method as the underlying thrif…
Browse files Browse the repository at this point in the history
…t interface does not implement it
  • Loading branch information
devdazed committed Feb 5, 2014
1 parent e717734 commit 9f5b60a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/connection.js
Expand Up @@ -97,7 +97,7 @@ function escapeCQL(val) {
if(val instanceof Buffer){
return val.toString('hex');
}

if(val instanceof uuid.UUID){
return val.toString();
}
Expand Down Expand Up @@ -366,18 +366,32 @@ Connection.prototype.authenticate = function(callback){
Connection.prototype.execute = function(){
var args = Array.prototype.slice.apply(arguments),
command = args.shift(),
callback = args.pop();
callback = args.pop(),
timer, calledBack = false,
self = this;

if(typeof callback !== 'function'){
args.push(callback);
callback = NOOP;
}

timer = setTimeout(function(){
if(!calledBack){
callback(new Error('Read Timed Out'));
self._connection.connection.destroy();
}
}, this.timeout);

/**
* Processes the return results of the query
* @private
*/
function onReturn(err, results){
clearTimeout(timer);
if(calledBack){
return;
}

if(err){
callback(errors.create(err));
} else {
Expand Down

0 comments on commit 9f5b60a

Please sign in to comment.