Files: cc048d2d98e1cd95038b14d5816dd19931a7b0fa / sinks / find.js
478 bytesRaw
1 | |
2 | |
3 | function id (e) { return e } |
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 | |
27 | |
28 | |
29 |
Built with git-ssb-web