diff --git a/index.js b/index.js index 6556e7ee..7952f92c 100644 --- a/index.js +++ b/index.js @@ -175,7 +175,11 @@ Cursor.prototype.end = util.deprecate(function(cb) { Cursor.prototype.close = function(cb) { if (this.state === 'done') { - return setImmediate(cb) + if (cb) { + return setImmediate(cb) + } else { + return + } } this._closePortal() this.state = 'done' diff --git a/test/close.js b/test/close.js index a1226be0..23fb7f9d 100644 --- a/test/close.js +++ b/test/close.js @@ -10,6 +10,16 @@ describe('close', function() { client.on('drain', client.end.bind(client)) }) + it('can close a finished cursor without a callback', function(done) { + const cursor = new Cursor(text) + this.client.query(cursor) + this.client.query('SELECT NOW()', done) + cursor.read(100, function(err) { + assert.ifError(err) + cursor.close() + }) + }) + it('closes cursor early', function(done) { const cursor = new Cursor(text) this.client.query(cursor)