Files: 6d8c497b8410ed867ce8d18379bf732e0cf1e5f6 / 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