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