corestore 7.0.14 → 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 +16 -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()
|
|
@@ -177,6 +188,8 @@ class CoreTracker {
|
|
|
177
188
|
|
|
178
189
|
const all = []
|
|
179
190
|
for (const core of this.map.values()) all.push(core.close())
|
|
191
|
+
this.map.clear()
|
|
192
|
+
|
|
180
193
|
return Promise.all(all)
|
|
181
194
|
}
|
|
182
195
|
|
|
@@ -350,7 +363,8 @@ class Corestore extends ReadyResource {
|
|
|
350
363
|
|
|
351
364
|
async _attachMaybe (muxer, discoveryKey) {
|
|
352
365
|
if (this.opened === false) await this.ready()
|
|
353
|
-
if (this.cores.
|
|
366
|
+
if (!this.cores.opened(toHex(discoveryKey)) && !(await this.storage.has(discoveryKey, { ifMigrated: true }))) return
|
|
367
|
+
if (this.closing) return
|
|
354
368
|
|
|
355
369
|
const core = this._openCore(discoveryKey, { createIfMissing: false })
|
|
356
370
|
|
|
@@ -515,7 +529,7 @@ class Corestore extends ReadyResource {
|
|
|
515
529
|
if (existing && !existing.closing) return existing
|
|
516
530
|
|
|
517
531
|
const core = Hypercore.createCore(this.storage, {
|
|
518
|
-
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...
|
|
519
533
|
eagerUpgrade: true,
|
|
520
534
|
notDownloadingLinger: opts.notDownloadingLinger,
|
|
521
535
|
allowFork: opts.allowFork !== false,
|