Files: 7aa21412f6c0bd6b84022d67ff8e51711eddb510 / find.js
475 bytesRaw
1 | |
2 | |
3 | var id = require('./util/id') |
4 | var prop = require('./util/prop') |
5 | var drain = require('./drain') |
6 | |
7 | module.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