Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js。为什么此管道抛出:错误:结束后写入?_Node.js_Node.js Stream - Fatal编程技术网

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()