Skip to content
Merged
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
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const {
SESSION_MOVED,
SESSION_NOT_WRITABLE,
SNAPSHOT_NOT_AVAILABLE,
DECODING_ERROR
DECODING_ERROR,
REQUEST_CANCELLED
} = require('hypercore-errors')

// Hypercore actually does not have any notion of max/min block sizes
Expand Down Expand Up @@ -736,6 +737,8 @@ class Hypercore extends EventEmitter {

if (!upgraded && remoteWait) {
const activeRequests = (opts && opts.activeRequests) || this.activeRequests
if (isRequestsDestroyed(activeRequests)) throw REQUEST_CANCELLED()

const req = this.core.replicator.addUpgrade(activeRequests)

try {
Expand All @@ -755,6 +758,7 @@ class Hypercore extends EventEmitter {
if (!isValidIndex(bytes)) throw ASSERTION('seek is invalid', this.discoveryKey)

const activeRequests = (opts && opts.activeRequests) || this.activeRequests
if (isRequestsDestroyed(activeRequests)) throw REQUEST_CANCELLED()

if (this.encryption && !this.core.manifest) {
const req = this.replicator.addUpgrade(activeRequests)
Expand All @@ -777,6 +781,7 @@ class Hypercore extends EventEmitter {

if (!this._shouldWait(opts, this.wait)) return null

if (isRequestsDestroyed(activeRequests)) throw REQUEST_CANCELLED()
const req = this.core.replicator.addSeek(activeRequests, s)

const timeout = opts && opts.timeout !== undefined ? opts.timeout : this.timeout
Expand Down Expand Up @@ -916,6 +921,7 @@ class Hypercore extends EventEmitter {
if (this.onwait) this.onwait(index, this)

const activeRequests = (opts && opts.activeRequests) || this.activeRequests
if (isRequestsDestroyed(activeRequests)) throw REQUEST_CANCELLED()

const force = opts ? opts.force === true : false
const req = this.core.replicator.addBlock(activeRequests, index, force)
Expand Down Expand Up @@ -1393,3 +1399,8 @@ function createDiscoveryKeyHandler(fn) {
return fn(id)
}
}

function isRequestsDestroyed(activeRequests) {
// TODO: move this to an object instead so we can store a property in next major
return activeRequests.length > 0 && activeRequests[0] === null
}
Loading