Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward preload to session #605

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,29 @@ class Hypercore extends EventEmitter {
throw SESSION_CLOSED('Cannot make sessions on a closing core')
}

const Clz = opts.class || Hypercore

return new Clz(null, this.key, this._loadSessionOpts(opts))
}

_loadSessionOpts (opts) {
if (this.opened === true) return this._getSessionOpts(opts)

return {
preload: new Promise((resolve, reject) => {
this.opening.then(() => resolve(this._getSessionOpts(opts)), reject)
})
}
}

_getSessionOpts (opts) {
const wait = opts.wait === false ? false : this.wait
const writable = opts.writable === false ? false : !this._readonly
const onwait = opts.onwait === undefined ? this.onwait : opts.onwait
const timeout = opts.timeout === undefined ? this.timeout : opts.timeout
const weak = opts.weak === undefined ? this.weak : opts.weak
const Clz = opts.class || Hypercore
const s = new Clz(null, this.key, {

return {
...opts,
core: this.core,
wait,
Expand All @@ -218,9 +234,7 @@ class Hypercore extends EventEmitter {
writable,
weak,
parent: this
})

return s
}
}

async setEncryptionKey (encryptionKey, opts) {
Expand Down
Loading