Skip to content
This repository was archived by the owner on Dec 28, 2022. It is now read-only.

Commit b54e24f

Browse files
authored
Add opts.onwait to constructor (#115)
1 parent d147c9e commit b54e24f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ Note that `tree`, `data`, and `bitfield` are normally heavily sparse files.
6666
valueEncoding: 'json' | 'utf-8' | 'binary', // defaults to binary
6767
encodeBatch: batch => { ... }, // optionally apply an encoding to complete batches
6868
keyPair: kp, // optionally pass the public key and secret key as a key pair
69-
encryptionKey: k // optionally pass an encryption key to enable block encryption
69+
encryptionKey: k, // optionally pass an encryption key to enable block encryption
70+
onwait: () => {} // hook that is called if gets are waiting for download
7071
}
7172
```
7273

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module.exports = class Hypercore extends EventEmitter {
7070
this.sessions = opts._sessions || [this]
7171
this.auth = opts.auth || null
7272
this.autoClose = !!opts.autoClose
73+
this.onwait = opts.onwait || null
7374

7475
this.closing = null
7576
this.opening = this._openSession(key, storage, opts)
@@ -662,6 +663,7 @@ module.exports = class Hypercore extends EventEmitter {
662663
} else {
663664
if (opts && opts.wait === false) return null
664665
if (opts && opts.onwait) opts.onwait(index)
666+
else if (this.onwait) this.onwait(index)
665667

666668
const activeRequests = (opts && opts.activeRequests) || this.activeRequests
667669

0 commit comments

Comments
 (0)