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)
|
this.gc2 = this.gc2.filter(filter)
|
||||||
delete op.gc
|
delete op.gc
|
||||||
}
|
}
|
||||||
destroy () {
|
* destroy () {
|
||||||
clearInterval(this.gcInterval)
|
clearInterval(this.gcInterval)
|
||||||
this.gcInterval = null
|
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) {
|
setUserId (userId) {
|
||||||
if (!this.userIdPromise.inProgress) {
|
if (!this.userIdPromise.inProgress) {
|
||||||
|
@ -46,6 +46,12 @@ module.exports = function (Y /* : any*/) {
|
|||||||
this.onevent = onevent
|
this.onevent = onevent
|
||||||
this.eventListeners = []
|
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
|
Call this when a new operation arrives. It will be executed right away if
|
||||||
there are no waiting operations, that you prematurely executed
|
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;
|
db: Y.AbstractDatabase;
|
||||||
connector: Y.AbstractConnector;
|
connector: Y.AbstractConnector;
|
||||||
share: {[key: string]: any};
|
share: {[key: string]: any};
|
||||||
|
options: Object;
|
||||||
*/
|
*/
|
||||||
constructor (opts, callback) {
|
constructor (opts, callback) {
|
||||||
this.options = opts
|
this.options = opts
|
||||||
@ -145,10 +146,17 @@ class YConfig {
|
|||||||
return this.connector.reconnect()
|
return this.connector.reconnect()
|
||||||
}
|
}
|
||||||
destroy () {
|
destroy () {
|
||||||
this.disconnect()
|
if (this.connector.destroy != null) {
|
||||||
this.db.destroy()
|
this.connector.destroy()
|
||||||
this.connector = null
|
} else {
|
||||||
this.db = null
|
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