@@ -2,6 +2,7 @@ const crypto = require('crypto')
2
2
const { EventEmitter } = require ( 'events' )
3
3
const { promisify } = require ( 'util' )
4
4
5
+ const { NanoresourcePromise : Nanoresource } = require ( 'nanoresource-promise/emitter' )
5
6
const HypercoreProtocol = require ( 'hypercore-protocol' )
6
7
const hyperswarm = require ( 'hyperswarm' )
7
8
const codecs = require ( 'codecs' )
@@ -13,7 +14,7 @@ const log = require('debug')('corestore:network')
13
14
const OUTER_STREAM = Symbol ( 'networker-outer-stream' )
14
15
const STREAM_PEER = Symbol ( 'networker-stream-peer' )
15
16
16
- class CorestoreNetworker extends EventEmitter {
17
+ class CorestoreNetworker extends Nanoresource {
17
18
constructor ( corestore , opts = { } ) {
18
19
super ( )
19
20
this . corestore = corestore
@@ -145,7 +146,7 @@ class CorestoreNetworker extends EventEmitter {
145
146
}
146
147
}
147
148
148
- listen ( ) {
149
+ _open ( ) {
149
150
const self = this
150
151
if ( this . swarm ) return
151
152
@@ -196,6 +197,10 @@ class CorestoreNetworker extends EventEmitter {
196
197
} )
197
198
}
198
199
200
+ listen ( ) {
201
+ return this . open ( )
202
+ }
203
+
199
204
status ( discoveryKey ) {
200
205
if ( Buffer . isBuffer ( discoveryKey ) ) discoveryKey = discoveryKey . toString ( 'hex' )
201
206
return this . _configurations . get ( discoveryKey )
@@ -250,12 +255,9 @@ class CorestoreNetworker extends EventEmitter {
250
255
return ext
251
256
}
252
257
253
- async close ( ) {
258
+ async _close ( ) {
254
259
if ( ! this . swarm ) return null
255
260
256
- const leaving = [ ...this . _joined ] . map ( dkey => this . _leave ( dkey ) )
257
- await Promise . all ( leaving )
258
-
259
261
for ( const ext of this . _extensions ) {
260
262
ext . destroy ( )
261
263
}
0 commit comments