diff --git a/src/Database.js b/src/Database.js index 4d249a91a3b04380e61812aabdca33731f9952cb..18da30a52b2a2753b410b2f43f6cb75d9fa358af 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 a851192bbb03ff66903ceb9bdfd19c9ffacc4e02..c0a0cc2c05b1f4adee9539e9126c6bbe1bad5001 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 3718f311b112b885a4a10bad56b92962bac50431..f62d9979bc19cd7bea040149e06d199fdb1cbda5 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 + }) } }