Files: 682c723635aac59a9a356df19d424bf23b1bb037 / util.js
771 bytesRaw
1 | var pull = require('pull-stream') |
2 | var Next = require('pull-next') |
3 | |
4 | exports.next = function (createStream, opts, property, range) { |
5 | |
6 | range = range || (opts.reverse ? 'lt' : 'gt') |
7 | property = property || 'timestamp' |
8 | |
9 | var last = null, count = -1 |
10 | return Next(function () { |
11 | if(last) { |
12 | if(count === 0) return |
13 | var value = opts[range] = get(last, property) |
14 | if(value == null) return |
15 | last = null |
16 | } |
17 | return pull( |
18 | createStream(opts), |
19 | pull.through(function (msg) { |
20 | count ++ |
21 | if(!msg.sync) { |
22 | last = msg |
23 | } |
24 | }, function (err) { |
25 | //retry on errors... |
26 | if(err) return count = -1 |
27 | //end stream if there were no results |
28 | if(last == null) last = {} |
29 | }) |
30 | ) |
31 | }) |
32 | } |
33 | |
34 |
Built with git-ssb-web