git ssb

2+

Dominic / pull-stream



Tree: 7aa21412f6c0bd6b84022d67ff8e51711eddb510

Files: 7aa21412f6c0bd6b84022d67ff8e51711eddb510 / find.js

475 bytesRaw
1'use strict'
2
3var id = require('./util/id')
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

Built with git-ssb-web