hypercore 10.18.1 → 10.18.2
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 +14 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -258,7 +258,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
async _openFromExisting (from, opts) {
|
|
261
|
-
await from.opening
|
|
261
|
+
if (!from.opened) await from.opening
|
|
262
262
|
|
|
263
263
|
// includes ourself as well, so the loop below also updates us
|
|
264
264
|
const sessions = this.sessions
|
|
@@ -279,7 +279,7 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
279
279
|
const isFirst = !opts._opening
|
|
280
280
|
|
|
281
281
|
if (!isFirst) await opts._opening
|
|
282
|
-
if (opts.preload) opts = { ...opts, ...(await opts.preload
|
|
282
|
+
if (opts.preload) opts = { ...opts, ...(await this._retryPreload(opts.preload)) }
|
|
283
283
|
|
|
284
284
|
const keyPair = (key && opts.keyPair)
|
|
285
285
|
? { ...opts.keyPair, publicKey: key }
|
|
@@ -329,6 +329,18 @@ module.exports = class Hypercore extends EventEmitter {
|
|
|
329
329
|
this.emit('ready')
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
+
async _retryPreload (preload) {
|
|
333
|
+
while (true) { // TODO: better long term fix is allowing lib/core.js creation from the outside...
|
|
334
|
+
const result = await preload()
|
|
335
|
+
const from = result && result.from
|
|
336
|
+
if (from) {
|
|
337
|
+
if (!from.opened) await from.ready()
|
|
338
|
+
if (from.closing) continue
|
|
339
|
+
}
|
|
340
|
+
return result
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
332
344
|
async _openCapabilities (keyPair, storage, opts) {
|
|
333
345
|
if (opts.from) return this._openFromExisting(opts.from, opts)
|
|
334
346
|
|