From 24e485e81e125dc95492591a6fc0db16a9525d7d Mon Sep 17 00:00:00 2001 From: Hetul Patel Date: Tue, 3 Oct 2017 18:13:40 -0700 Subject: [PATCH 1/2] Fix closing a finished cursor without supplying a callback --- index.js | 6 +++++- test/close.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 2c33a230c..af95d2875 100644 --- a/index.js +++ b/index.js @@ -149,7 +149,11 @@ Cursor.prototype.end = function (cb) { Cursor.prototype.close = function (cb) { if (this.state === 'done') { - return setImmediate(cb) + if (cb) { + return setImmediate(cb) + } else { + return + } } this.connection.close({type: 'P'}) this.connection.sync() diff --git a/test/close.js b/test/close.js index 59ea3c71a..a108fa87b 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) { + var cursor = new Cursor(text) + this.client.query(cursor) + this.client.query('SELECT NOW()', done) + cursor.read(100, function (err, res) { + assert.ifError(err) + cursor.close() + }) + }) + it('closes cursor early', function (done) { var cursor = new Cursor(text) this.client.query(cursor) From 124c89b173ca0d6faa9a9509b0b029aa4e864fe0 Mon Sep 17 00:00:00 2001 From: Hetul Patel Date: Fri, 13 Dec 2019 15:30:40 -0800 Subject: [PATCH 2/2] fix lint issues --- test/close.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/close.js b/test/close.js index b1557a6ac..23fb7f9de 100644 --- a/test/close.js +++ b/test/close.js @@ -14,13 +14,12 @@ describe('close', function() { const cursor = new Cursor(text) this.client.query(cursor) this.client.query('SELECT NOW()', done) - cursor.read(100, function (err, res) { + 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)