corestore 6.4.1 → 6.4.3

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.
Files changed (2) hide show
  1. package/index.js +12 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -60,6 +60,11 @@ module.exports = class Corestore extends EventEmitter {
60
60
  }
61
61
  }
62
62
 
63
+ _emitCore (name, core) {
64
+ this.emit(name, core)
65
+ if (this !== this._root) this._root.emit(name, core)
66
+ }
67
+
63
68
  _incFindingPeers () {
64
69
  if (++this._findingPeersCount !== 1) return
65
70
 
@@ -201,7 +206,7 @@ module.exports = class Corestore extends EventEmitter {
201
206
  this.cores.set(id, core)
202
207
  core.ready().then(() => {
203
208
  if (core.closing) return // extra safety here as ready is a tick after open
204
- this.emit('core-open', core)
209
+ this._emitCore('core-open', core)
205
210
  for (const { stream } of this._replicationStreams) {
206
211
  core.replicate(stream, { session: true })
207
212
  }
@@ -209,7 +214,7 @@ module.exports = class Corestore extends EventEmitter {
209
214
  this.cores.delete(id)
210
215
  })
211
216
  core.once('close', () => {
212
- this.emit('core-close', core)
217
+ this._emitCore('core-close', core)
213
218
  this.cores.delete(id)
214
219
  })
215
220
  core.on('conflict', (len, fork, proof) => {
@@ -258,12 +263,15 @@ module.exports = class Corestore extends EventEmitter {
258
263
  this._findingPeers.push(core.findingPeers())
259
264
  }
260
265
 
261
- core.once('close', () => {
266
+ const gc = () => {
262
267
  // technically better to also clear _findingPeers if we added it,
263
268
  // but the lifecycle for those are pretty short so prob not worth the complexity
264
269
  // as _decFindingPeers clear them all.
265
270
  this._sessions.delete(core)
266
- })
271
+ }
272
+
273
+ core.ready().catch(gc)
274
+ core.once('close', gc)
267
275
 
268
276
  return core
269
277
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.4.1",
3
+ "version": "6.4.3",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {