Commit 0e8042dde57ba8d7212909cd3677011b78124c5b
stop a series stream when you get to the end
Dominic Tarr committed on 6/22/2016, 12:03:07 AMParent: 3e002b3d827c2d8867edbf6541a3e6eadc4b32b6
Files changed
util.js | changed |
util.js | ||
---|---|---|
@@ -15,25 +15,42 @@ | ||
15 | 15 | return caller(decorator, element, value) || element |
16 | 16 | }, null) |
17 | 17 | } |
18 | 18 | |
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 | + | |
19 | 30 | exports.first = first |
20 | 31 | exports.decorate = decorate |
21 | 32 | |
22 | -exports.next = function (createStream, opts, range, property) { | |
33 | +exports.next = function (createStream, opts, property, range) { | |
23 | 34 | |
24 | 35 | range = range || opts.reverse ? 'lt' : 'gt' |
25 | 36 | property = property || 'timestamp' |
26 | 37 | |
27 | - var last = null | |
38 | + var last = null, count = -1 | |
28 | 39 | return Next(function () { |
29 | 40 | 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 | |
31 | 44 | } |
32 | 45 | return pull( |
33 | 46 | createStream(opts), |
34 | 47 | pull.through(function (msg) { |
48 | + count ++ | |
35 | 49 | if(!msg.sync) last = msg |
50 | + }, function (err) { | |
51 | + //retry on errors... | |
52 | + if(err) count = -1 | |
36 | 53 | }) |
37 | 54 | ) |
38 | 55 | }) |
39 | 56 | } |
Built with git-ssb-web