Add `opts.onwait` to constructor
MODIFY
README.md
README.md
@@ -66,7 +66,8 @@ Note that `tree`, `data`, and `bitfield` are normally heavily sparse files.
valueEncoding: 'json' | 'utf-8' | 'binary', // defaults to binary
encodeBatch: batch => { ... }, // optionally apply an encoding to complete batches
keyPair: kp, // optionally pass the public key and secret key as a key pair
- encryptionKey: k // optionally pass an encryption key to enable block encryption
+ encryptionKey: k, // optionally pass an encryption key to enable block encryption
+ onwait: () => {} // hook that is called if gets are waiting for download
}
```

MODIFY
index.js
index.js
@@ -70,6 +70,7 @@ module.exports = class Hypercore extends EventEmitter {
this.sessions = opts._sessions || [this]
this.auth = opts.auth || null
this.autoClose = !!opts.autoClose
+ this.onwait = opts.onwait || null
this.closing = null
this.opening = this._openSession(key, storage, opts)
@@ -662,6 +663,7 @@ module.exports = class Hypercore extends EventEmitter {
} else {
if (opts && opts.wait === false) return null
if (opts && opts.onwait) opts.onwait(index)
+ else if (this.onwait) this.onwait(index)
const activeRequests = (opts && opts.activeRequests) || this.activeRequests

Add `opts.onwait` to constructor (#115)