diff --git a/README.md b/README.md index b3137f7..1b6c79f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ r.connect( //... // Make a query to get a cursor r.table('myTable').run(connection, function(err, cursor) { var stream = new CursorStream(cursor); - cursor.pipe(//... do whatever you want with your stream ! + stream.pipe(//... do whatever you want with your stream ! }); ``` diff --git a/index.js b/index.js index a339a1f..809f64f 100644 --- a/index.js +++ b/index.js @@ -16,12 +16,12 @@ function CursorStream(cursor) { } CursorStream.prototype._read = function read() { - if (!(this._cursor && this._cursor.hasNext())) { - this.push(null); - return; - } this._cursor.next(function (err, item) { if (err) { + if (((err.name === "RqlDriverError") && err.message === "No more rows in the cursor.")) { + this.push(null); + return; + } this.emit('error', err); return; } @@ -29,4 +29,4 @@ CursorStream.prototype._read = function read() { read.bind(this); } }.bind(this)); -}; \ No newline at end of file +};