Skip to content

Commit

Permalink
close take opts object
Browse files Browse the repository at this point in the history
  • Loading branch information
chm-diederichs committed Sep 24, 2024
1 parent 4b49519 commit 710abe4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ module.exports = class Hypercore extends EventEmitter {
return !this._readonly && !!(this.keyPair && this.keyPair.secretKey)
}

async close (error, { force = !!error } = {}) {
async close ({ error, force = !!error } = {}) {
if (force) {
if (this.closing) await this.closing

Expand All @@ -477,7 +477,7 @@ module.exports = class Hypercore extends EventEmitter {
return this._closeAllSessions(err)
}

async _close (err, force) {
async _close (error, force) {
if (this.opened === false) await this.opening

const i = this.sessions.indexOf(this)
Expand All @@ -497,7 +497,7 @@ module.exports = class Hypercore extends EventEmitter {

if (this.replicator !== null) {
this.replicator.findingPeers -= this._findingPeers
this.replicator.clearRequests(this.activeRequests, err)
this.replicator.clearRequests(this.activeRequests, error)
this.replicator.updateActivity(this._active ? -1 : 0)
}

Expand All @@ -508,7 +508,7 @@ module.exports = class Hypercore extends EventEmitter {
await this.state.unref()

// if this is the last session and we are auto closing, trigger that first to enforce error handling
if (this.sessions.length === 1 && this.core.state.active === 1 && this.autoClose) await this.sessions[0].close(err)
if (this.sessions.length === 1 && this.core.state.active === 1 && this.autoClose) await this.sessions[0].close({ error })
// emit "fake" close as this is a session

if (this.sessions.length !== 0 || !force) {
Expand Down Expand Up @@ -655,7 +655,7 @@ module.exports = class Hypercore extends EventEmitter {
const sessions = [...this.sessions]

const all = []
for (const s of sessions) all.push(s.close(err, { force: false })) // force false or else infinite recursion
for (const s of sessions) all.push(s.close({ error: err, force: false })) // force false or else infinite recursion
await Promise.allSettled(all)
}

Expand Down

0 comments on commit 710abe4

Please sign in to comment.