git ssb

2+

Dominic / pull-stream



Tree: f2094a0360975cb77c09e9635cf7ce2801178945

Files: f2094a0360975cb77c09e9635cf7ce2801178945 / sinks / find.js

478 bytesRaw
1'use strict'
2
3function id (e) { return e }
4var prop = require('../util/prop')
5var drain = require('./drain')
6
7module.exports = function find (test, cb) {
8 var ended = false
9 if(!cb)
10 cb = test, test = id
11 else
12 test = prop(test) || id
13
14 return drain(function (data) {
15 if(test(data)) {
16 ended = true
17 cb(null, data)
18 return false
19 }
20 }, function (err) {
21 if(ended) return //already called back
22 cb(err === true ? null : err, null)
23 })
24}
25
26
27
28
29

Built with git-ssb-web