Skip to content

Commit 3f03df0

Browse files
committed
await open in listen
1 parent 320d2d4 commit 3f03df0

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

index.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,27 @@ class CorestoreNetworker extends Nanoresource {
197197
})
198198
}
199199

200+
async _close () {
201+
if (!this.swarm) return null
202+
203+
for (const ext of this._extensions) {
204+
ext.destroy()
205+
}
206+
this._extensions.clear()
207+
208+
for (const stream of this.streams) {
209+
stream.destroy()
210+
}
211+
212+
return new Promise((resolve, reject) => {
213+
this.swarm.destroy(err => {
214+
if (err) return reject(err)
215+
this.swarm = null
216+
return resolve()
217+
})
218+
})
219+
}
220+
200221
listen () {
201222
return this.open()
202223
}
@@ -213,7 +234,7 @@ class CorestoreNetworker extends Nanoresource {
213234
async configure (discoveryKey, opts = {}) {
214235
if (this.swarm && this.swarm.destroyed) return null
215236
if (!this.swarm) {
216-
this.listen()
237+
await this.listen()
217238
return this.configure(discoveryKey, opts)
218239
}
219240
const self = this
@@ -255,26 +276,6 @@ class CorestoreNetworker extends Nanoresource {
255276
return ext
256277
}
257278

258-
async _close () {
259-
if (!this.swarm) return null
260-
261-
for (const ext of this._extensions) {
262-
ext.destroy()
263-
}
264-
this._extensions.clear()
265-
266-
for (const stream of this.streams) {
267-
stream.destroy()
268-
}
269-
270-
return new Promise((resolve, reject) => {
271-
this.swarm.destroy(err => {
272-
if (err) return reject(err)
273-
this.swarm = null
274-
return resolve()
275-
})
276-
})
277-
}
278279
}
279280

280281
module.exports = CorestoreNetworker

0 commit comments

Comments
 (0)