reconnect only when disconnected (and reverse)

This commit is contained in:
Kevin Jahns 2016-11-10 12:54:01 +01:00
parent 34997f940b
commit c9d1f34864

View File

@ -154,6 +154,7 @@ class YConfig {
this.options = opts
this.db = new Y[opts.db.name](this, opts.db)
this.connector = new Y[opts.connector.name](this, opts.connector)
this.connected = true
}
init (callback) {
var opts = this.options
@ -190,10 +191,20 @@ class YConfig {
return this.connector.isSynced
}
disconnect () {
return this.connector.disconnect()
if (this.connected) {
this.connected = false
return this.connector.disconnect()
} else {
return Promise.resolve()
}
}
reconnect () {
return this.connector.reconnect()
if (!this.connected) {
this.connected = true
return this.connector.reconnect()
} else {
return Promise.resolve()
}
}
destroy () {
var self = this