dht-rpc 6.4.0 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/index.js +4 -2
- package/package.json +1 -1
- package/test.js +31 -0
package/README.md
CHANGED
|
@@ -158,6 +158,10 @@ Emitted when the routing table is fully bootstrapped. Emitted as a conveinience.
|
|
|
158
158
|
|
|
159
159
|
Emitted when the underlying UDX socket is listening. Emitted as a conveinience.
|
|
160
160
|
|
|
161
|
+
#### `node.on('ready')`
|
|
162
|
+
|
|
163
|
+
Emitted when the node is fully bootstrapped etc.
|
|
164
|
+
|
|
161
165
|
#### `node.on('persistent')`
|
|
162
166
|
|
|
163
167
|
Emitted when the node is no longer in ephemeral mode.
|
|
@@ -174,6 +178,10 @@ it will switch from persistent mode to ephemeral again.
|
|
|
174
178
|
|
|
175
179
|
Emitted when the network interfaces of the computer change.
|
|
176
180
|
|
|
181
|
+
#### `node.on('close')`
|
|
182
|
+
|
|
183
|
+
Will be emitted after `node.destroy()` is completed.
|
|
184
|
+
|
|
177
185
|
#### `node.refresh()`
|
|
178
186
|
|
|
179
187
|
Refresh the routing table by looking up a random node in the background.
|
package/index.js
CHANGED
|
@@ -226,10 +226,12 @@ class DHT extends EventEmitter {
|
|
|
226
226
|
this._backgroundQuery(node ? node.id : this.table.id).on('error', noop)
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
destroy () {
|
|
229
|
+
async destroy () {
|
|
230
|
+
const emitClose = !this.destroyed
|
|
230
231
|
this.destroyed = true
|
|
231
232
|
clearInterval(this._tickInterval)
|
|
232
|
-
|
|
233
|
+
await this.io.destroy()
|
|
234
|
+
if (emitClose) this.emit('close')
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
_request (to, internal, command, target, value, session, onresponse, onerror) {
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -417,6 +417,37 @@ test('request session, destroy all', async function (t) {
|
|
|
417
417
|
}
|
|
418
418
|
})
|
|
419
419
|
|
|
420
|
+
test('close event', async function (t) {
|
|
421
|
+
t.plan(1)
|
|
422
|
+
|
|
423
|
+
const node = new DHT()
|
|
424
|
+
|
|
425
|
+
node.once('close', function () {
|
|
426
|
+
t.pass('node closed')
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
await node.destroy()
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
test('close event is only emitted once', async function (t) {
|
|
433
|
+
t.plan(2)
|
|
434
|
+
|
|
435
|
+
const node = new DHT()
|
|
436
|
+
let count = 0
|
|
437
|
+
|
|
438
|
+
node.on('close', function () {
|
|
439
|
+
if (++count >= 2) t.fail('close was emitted more than once')
|
|
440
|
+
else t.pass('node closed')
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
await Promise.all([node.destroy(), node.destroy()])
|
|
444
|
+
|
|
445
|
+
await node.destroy()
|
|
446
|
+
await node.destroy()
|
|
447
|
+
|
|
448
|
+
t.pass()
|
|
449
|
+
})
|
|
450
|
+
|
|
420
451
|
async function freePort () {
|
|
421
452
|
const udx = new UDX()
|
|
422
453
|
const sock = udx.createSocket()
|