git ssb

16+

Dominic / patchbay



Commit 0e8042dde57ba8d7212909cd3677011b78124c5b

stop a series stream when you get to the end

Dominic Tarr committed on 6/22/2016, 12:03:07 AM
Parent: 3e002b3d827c2d8867edbf6541a3e6eadc4b32b6

Files changed

util.jschanged
util.jsView
@@ -15,25 +15,42 @@
1515 return caller(decorator, element, value) || element
1616 }, null)
1717 }
1818
19+function get(obj, path) {
20+ if(obj == null) return obj
21+ if('string' === typeof path) return obj[path]
22+ for(var i = 0; i < path.length; i++) {
23+ obj = obj[path[i]]
24+ if(obj == null) return
25+ }
26+ return obj
27+
28+}
29+
1930 exports.first = first
2031 exports.decorate = decorate
2132
22-exports.next = function (createStream, opts, range, property) {
33+exports.next = function (createStream, opts, property, range) {
2334
2435 range = range || opts.reverse ? 'lt' : 'gt'
2536 property = property || 'timestamp'
2637
27- var last = null
38+ var last = null, count = -1
2839 return Next(function () {
2940 if(last) {
30- opts[range] = last[property]
41+ if(count === 0) return
42+ var value = opts[range] = get(last, property)
43+ if(value === stop) return null
3144 }
3245 return pull(
3346 createStream(opts),
3447 pull.through(function (msg) {
48+ count ++
3549 if(!msg.sync) last = msg
50+ }, function (err) {
51+ //retry on errors...
52+ if(err) count = -1
3653 })
3754 )
3855 })
3956 }

Built with git-ssb-web