Files: f8ac0ce23d5685c236e76ded42ded5572d52f53f / tag / pull / find.js
757 bytesRaw
1 | const nest = require('depnest') |
2 | const defer = require('pull-defer') |
3 | const pull = require('pull-stream') |
4 | const onceTrue = require('mutant/once-true') |
5 | |
6 | exports.gives = nest('tag.pull.find') |
7 | |
8 | exports.needs = nest({ |
9 | 'sbot.obs.connection': 'first' |
10 | }) |
11 | |
12 | exports.create = function(api) { |
13 | return nest({ 'tag.pull.find': find }) |
14 | |
15 | function find(opts) { |
16 | return StreamWhenConnected(api.sbot.obs.connection, (sbot) => { |
17 | if (!sbot.tags || !sbot.tags.stream) return pull.empty() |
18 | return sbot.tags.stream(opts) |
19 | }) |
20 | } |
21 | } |
22 | |
23 | // COPIED from patchcore 'feed.pull.private' |
24 | function StreamWhenConnected (connection, fn) { |
25 | var stream = defer.source() |
26 | onceTrue(connection, function (connection) { |
27 | stream.resolve(fn(connection)) |
28 | }) |
29 | return stream |
30 | } |
31 |
Built with git-ssb-web