corestore 7.0.15 → 7.0.16
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/index.js +13 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -119,6 +119,11 @@ class CoreTracker {
|
|
|
119
119
|
return core
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
opened (id) {
|
|
123
|
+
const core = this.map.get(id)
|
|
124
|
+
return !!(core && core.opened && !core.closing)
|
|
125
|
+
}
|
|
126
|
+
|
|
122
127
|
get (id) {
|
|
123
128
|
// we allow you do call this from the outside, so support normal buffers also
|
|
124
129
|
if (b4a.isBuffer(id)) id = b4a.toString(id, 'hex')
|
|
@@ -156,6 +161,12 @@ class CoreTracker {
|
|
|
156
161
|
}
|
|
157
162
|
|
|
158
163
|
gc (core) {
|
|
164
|
+
// if not opened, gc immediately
|
|
165
|
+
if (!core.opened) {
|
|
166
|
+
this._gc(core)
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
|
|
159
170
|
core.gc = 1 // first strike
|
|
160
171
|
this._gcing.add(core)
|
|
161
172
|
if (this._gcing.size === 1) this._startGC()
|
|
@@ -352,7 +363,7 @@ class Corestore extends ReadyResource {
|
|
|
352
363
|
|
|
353
364
|
async _attachMaybe (muxer, discoveryKey) {
|
|
354
365
|
if (this.opened === false) await this.ready()
|
|
355
|
-
if (this.cores.
|
|
366
|
+
if (!this.cores.opened(toHex(discoveryKey)) && !(await this.storage.has(discoveryKey, { ifMigrated: true }))) return
|
|
356
367
|
if (this.closing) return
|
|
357
368
|
|
|
358
369
|
const core = this._openCore(discoveryKey, { createIfMissing: false })
|
|
@@ -518,7 +529,7 @@ class Corestore extends ReadyResource {
|
|
|
518
529
|
if (existing && !existing.closing) return existing
|
|
519
530
|
|
|
520
531
|
const core = Hypercore.createCore(this.storage, {
|
|
521
|
-
preopen: existing ? existing.closing : null, // always wait for the prev one to close first in any case...
|
|
532
|
+
preopen: (existing && existing.opened) ? existing.closing : null, // always wait for the prev one to close first in any case...
|
|
522
533
|
eagerUpgrade: true,
|
|
523
534
|
notDownloadingLinger: opts.notDownloadingLinger,
|
|
524
535
|
allowFork: opts.allowFork !== false,
|