I wrote the next simply code:
gulp.task('test', function () {
var throughStream = through.obj(function (data, enc, next) {
this.push(data);
next();
});
function processStr(str, cb, parentStream) {
var stream = new Stream.Readable();
stream.push(str);
stream.push(null);
stream.pipe(throughStream);
stream.on('data', function (data) {
});
stream.once('end', function () {
cb();
});
}
var stream = new Stream.Readable();
stream.push("str 1 ");
stream.push("str 2 ");
stream.push("str 3 ");
stream.push(null);
stream.pipe(through.obj(function (data, enc, next) {
processStr(data, next, this);
}));
});
Line: stream.pipe(throughStream);
throws error "write after end".
But if I move var throughStream
into processStr function then all is okey.
Or if I delete stream.once('end', ...)
then it also works good.
So, I can't understand why does it happen?