Node.js。为什么此管道抛出:错误:结束后写入?
我写了下一个简单的代码:Node.js。为什么此管道抛出:错误:结束后写入?,node.js,node.js-stream,Node.js,Node.js Stream,我写了下一个简单的代码: 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(
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);
}));
});
行:stream.pipe(直通流)代码>抛出错误“结束后写入”
但如果我将var通过流
移动到processStr函数中,那么一切都正常了
或者,如果我删除stream.once('end',…)
,那么它也可以正常工作
所以,我不明白为什么会发生这种情况?在这里大口大口喝的目的是什么?我需要这个来完成大口大口大口的任务。大口大口大口是你问题的一部分吗?这是原因吗?你在那里做了很多。为什么移动思维流是一个问题?我很确定这是关于打两次电话回叫。可能将.once()
部件向上移动也会解决此问题。还要确保您执行了返回cb()