implemented destroy & updated disconnect
This commit is contained in:
parent
bd54a43a33
commit
da7e67d97d
@ -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) {
|
||||
|
@ -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
|
||||
|
16
src/y.js
16
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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user