git ssb

4+

Dominic / scuttlebot



Commit eb053658d95d72c0e99e5f92e1cb6794d99f7c44

call fn with same `this` context in hooked function. emit "replicate:finish" to fit tested api. make sure sequence defaults to 0

Dominic Tarr committed on 10/3/2016, 3:59:50 AM
Parent: e5d0b7d8bace9ec48ab12ec7a1a40872a050acad

Files changed

plugins/replicate.jschanged
plugins/replicate.jsView
@@ -82,8 +82,11 @@
8282 var seq = upto.sequence || upto.seq
8383 to_recv[upto.id] = Math.max(to_recv[upto.id] || 0, seq)
8484 if(this._emit) this._emit('call:createHistoryStream', args[0])
8585
86 + //if we are calling this locally, skip cleverness
87 + if(this===sbot) return fn.call(this, upto)
88 +
8689 debounce.set()
8790
8891 //handle creating lots of histor streams efficiently.
8992 //maybe this could be optimized in map-filter-reduce queries instead?
@@ -98,9 +101,9 @@
98101 pushable.push(p)
99102 pushable.sequence = upto.sequence
100103 return p
101104 }
102- return fn(upto)
105 + return fn.call(this, upto)
103106 })
104107
105108 // collect the IDs of feeds we want to request
106109 var opts = config.replication || {}
@@ -172,26 +175,26 @@
172175
173176 sbot.on('rpc:connect', function(rpc) {
174177 // this is the cli client, just ignore.
175178 if(rpc.id === sbot.id) return
176-
177179 //check for local peers, or manual connections.
178180 localPeers()
179181 var drain
180182 sbot.emit('replicate:start', rpc)
181-
183 + rpc.on('closed', function () {
184 + sbot.emit('replicate:finish', to_send)
185 + })
182186 var SYNC = false
183187 pull(
184188 upto({live: opts.live}),
185189 drain = pull.drain(function (upto) {
186190 if(upto.sync) return
187-
188191 feeds++
189192 debounce.set()
190193 pull(
191194 rpc.createHistoryStream({
192195 id: upto.id,
193- seq: (upto.sequence || upto.seq) + 1,
196 + seq: (upto.sequence || upto.seq || 0) + 1,
194197 live: true,
195198 keys: false
196199 }),
197200 sbot.createWriteStream(function (err) {
@@ -216,4 +219,11 @@
216219 }
217220 }
218221
219222
223 +
224 +
225 +
226 +
227 +
228 +
229 +

Built with git-ssb-web