Skip to content

Commit c62794d

Browse files
mafintoshandrewosh
authored andcommitted
unconfigure should not bump priority if it is a no-op
1 parent 6f62f70 commit c62794d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class CorestoreNetworker extends Nanoresource {
229229
if (this.swarm && this.swarm.destroyed) return Promise.resolve()
230230

231231
const id = Symbol('id')
232-
const prom = this._configure(discoveryKey, opts, id)
232+
const prom = this._configure(discoveryKey, opts, id, false)
233233
const keyString = toString(discoveryKey)
234234
const prev = this._configurations.get(keyString) || { lookup: false, announce: false, id: null }
235235

@@ -252,23 +252,25 @@ class CorestoreNetworker extends Nanoresource {
252252
const conf = this._configurations.get(keyString)
253253

254254
if (!conf || conf.id !== prom.configureId) return
255-
return this._configure(discoveryKey, prom.previous, prom.previous.id)
255+
return this._configure(discoveryKey, prom.previous, prom.previous.id, true)
256256
}
257257

258-
async _configure (discoveryKey, opts = {}, id) {
258+
async _configure (discoveryKey, opts, id, isUnconfigure) {
259259
const config = {
260260
announce: opts.announce !== false,
261261
lookup: opts.lookup !== false
262262
}
263263
opts = { ...opts, ...config, id }
264264

265265
const keyString = toString(discoveryKey)
266+
const current = this._configurations.get(keyString)
266267

267268
if (id) this._configurations.set(keyString, opts)
268269
else this._configurations.delete(keyString)
269270

270271
const joining = config.announce || config.lookup
271272
if (joining) {
273+
if (isUnconfigure && current && current.lookup === config.lookup && current.announce === config.announce) return
272274
return this._join(discoveryKey, opts)
273275
} else {
274276
return this._leave(discoveryKey)

0 commit comments

Comments
 (0)