From f17eea29969537794eec436187610f77e66c3f38 Mon Sep 17 00:00:00 2001 From: k2s Date: Thu, 6 Jun 2019 00:59:52 +0200 Subject: [PATCH 1/2] add: method allDbsEnsureClosed to close pouch__all_dbs__ DB --- lib/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/index.js b/lib/index.js index 4433c38..f5b801c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -141,6 +141,21 @@ module.exports = function (Pouch) { }); }, callback); }); + + Pouch.allDbsEnsureClosed = utils.toPromise(function (callback) { + queue.add(function (callback) { + if (!pouch) return callback(); + + pouch.close().then(function () { + pouch = null; + cache = null; + callback(); + }).catch(/* istanbul ignore next */ function (err) { + console.error(err); + callback(err); + }); + }, callback); + }); }; /* istanbul ignore next */ From 4cadf9060657c70af92c3e96485d27eabadaa80d Mon Sep 17 00:00:00 2001 From: k2s Date: Thu, 6 Jun 2019 01:14:30 +0200 Subject: [PATCH 2/2] fix: precondition_failed/Database not open if pouch__all_dbs__ was never used, close() will throw precondition_failed/Database not open error --- lib/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index f5b801c..2c8209c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -151,8 +151,9 @@ module.exports = function (Pouch) { cache = null; callback(); }).catch(/* istanbul ignore next */ function (err) { - console.error(err); - callback(err); + pouch = null; + cache = null; + callback(); }); }, callback); });