您如何使用事件流暂停和恢复Gulp流?

时间:2018-07-10 00:59:57

标签: node.js gulp event-stream

我正在尝试将npm软件包克隆到客户端位置,因此我创建了多个流来完成此操作,并将它们合并以从<a href = "somelink"> Text <div id="div">Content</div> </a> <br/> <span id="result"></span> <script> document.getElementById("div").addEventListener("click", function(event){ event.preventDefault(); //you may also want to use event.stopPropagation() to stop the event bubbling down the DOM tree myFunc(); }); function myFunc(){ document.getElementById("result").innerHTML = "Function myFunc called."; } </script>返回。但是,据我了解,我将需要暂停流以使任务获得正确的退出。

以下代码运行无错误,但是如果我注释gulp.task()行。当我希望所有流都无法到达其return时,仍然会复制其中一个包。为什么所有的流都没有暂停?

gulp.dest()

1 个答案:

答案 0 :(得分:0)

event-stream中可能存在错误,因为以下代码仅适用于merge-stream

var merge = require('merge-stream')
    , eventStream = require('event-stream') 
    ;

gulp.task('init:client-packages', function() {
    let streams = [];

    // Load project client-side dependencies
    for (let prj in projects) {
        for (let pkg in projects[prj].dependencies) {
            streams.push(
                gulp.src('./node_modules/' + pkg + '/**')
                    .pipe(gulp.dest(projects[prj].dependencies[pkg]))
            );
        }
    }

    // Merge source streams
    return merge(streams);
    // --OR--
    return eventStream.merge(streams); // Results in message below.
});

如上所述,event-stream无法正确关闭任务。输出如下:

[23:36:46] Starting 'init:client-packages'...
[23:36:47] The following tasks did not complete: init:client-packages
[23:36:47] Did you forget to signal async completion?
Process terminated with code 1.