-
Notifications
You must be signed in to change notification settings - Fork 2
/
through.js
32 lines (29 loc) · 1000 Bytes
/
through.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var assert = require('assert')
module.exports = function Through () {
var isResolving = false
var ended = false
var errd = false
var aborted = false
return function sink (source) {
return function newSource (abort, next) {
assert(!aborted, 'should not call source after aborting')
assert(!isResolving, 'should not call source before it returns')
aborted = abort || aborted
isResolving = true
source(abort, function onNext (end, data) {
isResolving = false
assert(!ended, 'should not emit more after ending')
assert(!errd, 'should not emit more after error')
if (end === true) {
ended = true
return next(end)
}
if (end) {
errd = true
return next(end)
}
next(end, data)
})
}
}
}