Comparing version 4.2.2 to 4.2.3
21
mux.js
var protocol = require('hypercore-protocol') | ||
var once = require('once') | ||
var readify = require('./ready') | ||
@@ -41,2 +42,3 @@ var inherits = require('inherits') | ||
self._activeFeedStreams = {} | ||
self._pendingReplicationFeeds = 2 | ||
@@ -213,3 +215,3 @@ var stream = this.stream = protocol(Object.assign({},opts,{ | ||
this.emit('replicate', keys, startFeedReplication) | ||
this.emit('replicate', keys, once(startFeedReplication)) | ||
@@ -219,8 +221,18 @@ return keys | ||
function startFeedReplication(feeds){ | ||
if (!Array.isArray(feeds)) feeds = [feeds] | ||
--self._pendingReplicationFeeds | ||
// Decrement back down the expected feeds. | ||
self.stream.expectedFeeds-- | ||
if (!Array.isArray(feeds)) feeds = [feeds] | ||
self.stream.expectedFeeds += feeds.length | ||
if (self._pendingReplicationFeeds === 0 && self.stream.expectedFeeds === 0) { | ||
debug(self._id, '[REPLICATION] terminating mux: no feeds to sync') | ||
self.stream.expectedFeeds = 1 | ||
self._feed.close() | ||
return | ||
} | ||
// only the feeds passed to `feeds` option will be replicated (sent or received) | ||
@@ -262,7 +274,2 @@ // hypercore-protocol has built in protection against receiving unexpected/not asked for data. | ||
}) | ||
if (feeds.length === 0) { | ||
debug('[REPLICATION] terminating mux: no feeds to sync') | ||
self._feed.close() | ||
} | ||
} | ||
@@ -269,0 +276,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Stephen Whitmore <sww@eight.net>", | ||
"version": "4.2.2", | ||
"version": "4.2.3", | ||
"repository": { | ||
@@ -23,2 +23,3 @@ "url": "git://github.com/noffle/multifeed.git" | ||
"mutexify": "^1.2.0", | ||
"once": "^1.4.0", | ||
"random-access-file": "^2.0.1", | ||
@@ -25,0 +26,0 @@ "random-access-memory": "^3.1.1", |
26396
613
8
+ Addedonce@^1.4.0
+ Addedonce@1.4.0(transitive)
+ Addedwrappy@1.0.2(transitive)