-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
21 lines (21 loc) · 702 Bytes
/
index.js
File metadata and controls
21 lines (21 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module.exports = function Catch (onError) {
onError = onError || function noop () {}
var errd
return function sink (read) {
return function source (abort, cb) {
read(abort, function onNext (end, data) {
if (errd) return cb(true)
if (end && end !== true) { // if error
var _end = onError(end)
if (_end === false) return cb(end)
if (_end && _end !== true) {
errd = true
return cb(null, _end)
}
return cb(true)
}
cb(end, data)
})
}
}
}