Skip to content

Commit ea2bc76

Browse files
committed
only set _update listener once. good spotting @Raynos
1 parent ddfa9be commit ea2bc76

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ sb.createStream = function (opts) {
143143
sources = data.clock
144144

145145
i.each(self.history(sources), function (data) {d._data(data)})
146+
147+
//the _update listener must be set after the history is queued.
148+
//otherwise there is a race between the first client message
149+
//and the next update (which may come in on another stream)
150+
//this problem will probably not be encountered until you have
151+
//thousands of scuttlebutts.
152+
146153
self.on('_update', onUpdate)
147154

148155
d._data('SYNC')
@@ -218,14 +225,6 @@ sb.createStream = function (opts) {
218225
if(!d.writable && !opts.clock)
219226
start({clock:{}})
220227

221-
//if tail, and writable,
222-
//the _update listener must be set after the history is queued.
223-
//otherwise there is a race between the first client message
224-
//and the next update (which may come in on another stream)
225-
//this problem will probably not be encountered until you have
226-
//thousands of scuttlebutts.
227-
else if(tail)
228-
self.on('_update', onUpdate)
229228
} else if (opts.sendClock) {
230229
//send my current clock.
231230
//so the other side knows what to send

0 commit comments

Comments
 (0)