From da7e67d97da3c064ff54b6434a691e1176266983 Mon Sep 17 00:00:00 2001 From: Kevin Jahns <kevin.jahns@rwth-aachen.de> Date: Tue, 16 Feb 2016 15:51:12 +0100 Subject: [PATCH] implemented destroy & updated disconnect --- src/Database.js | 10 +++++++++- src/Utils.js | 6 ++++++ src/y.js | 16 ++++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Database.js b/src/Database.js index 4d249a91..18da30a5 100644 --- a/src/Database.js +++ b/src/Database.js @@ -176,9 +176,17 @@ module.exports = function (Y /* :any */) { this.gc2 = this.gc2.filter(filter) delete op.gc } - destroy () { + * destroy () { clearInterval(this.gcInterval) this.gcInterval = null + for(var key in this.initializedTypes) { + var type = this.initializedTypes[key] + if (type._destroy != null) { + type._destroy() + } else { + console.error('The type you included does not provide destroy functionality, it will remain in memory (updating your packages will help).') + } + } } setUserId (userId) { if (!this.userIdPromise.inProgress) { diff --git a/src/Utils.js b/src/Utils.js index a851192b..c0a0cc2c 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -46,6 +46,12 @@ module.exports = function (Y /* : any*/) { this.onevent = onevent this.eventListeners = [] } + destroy () { + this.waiting = null + this.awaiting = null + this.onevent = null + this.eventListeners = null + } /* Call this when a new operation arrives. It will be executed right away if there are no waiting operations, that you prematurely executed diff --git a/src/y.js b/src/y.js index 3718f311..f62d9979 100644 --- a/src/y.js +++ b/src/y.js @@ -108,6 +108,7 @@ class YConfig { db: Y.AbstractDatabase; connector: Y.AbstractConnector; share: {[key: string]: any}; + options: Object; */ constructor (opts, callback) { this.options = opts @@ -145,10 +146,17 @@ class YConfig { return this.connector.reconnect() } destroy () { - this.disconnect() - this.db.destroy() - this.connector = null - this.db = null + if (this.connector.destroy != null) { + this.connector.destroy() + } else { + this.connector.disconnect() + } + var self = this + this.db.requestTransaction(function * () { + yield* self.db.destroy() + self.connector = null + self.db = null + }) } } -- GitLab