question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support returning multiple streams from gulp.task

See original GitHub issue

Currently when you are dealing with async streams, and want Gulp to know when the task is finished, you have 3 options:

  1. Accept a callback
  2. Return a stream
  3. Return a promise

Could this be extended to include Return an array of streams, so the task is recognized as finished when all the streams are finished.

Currently I am using the following function as workaround:

function getStreamsFinishedPromise(streams){
    var deferred = Q.defer();
    var runningStreams = streams.length;

    streams.forEach(function(stream){
        stream.pipe(es.wait(function(){
            runningStreams--;
            if(runningStreams === 0){
                deferred.resolve();
            }
        }));
    });

    return deferred.promise;
}

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mgcreacommented, May 30, 2014

@contra @sqs, the recipe does not work for me:

// VIEWS
//
var jade = require('gulp-jade');
var safeJade = combine(jade({pretty: true}));
safeJade.on('error', function(err) {
  gutil.log(chalk.red(util.format('Plugin error: %s', err.message)));
});
var wiredep = require('wiredep').stream;
var through2 = require('through2');
var merge = require('merge-stream');

gulp.task('views:src', function() {

  return merge(
    gulp.src(paths.views, {cwd: paths.src, base: paths.src})
      .pipe(changed(paths.tmp))
      .pipe(safeJade)
      .pipe(gulp.dest(paths.tmp))
      .pipe(connect.reload()),
    gulp.src(paths.index, {cwd: paths.src, base: paths.src})
      .pipe(changed(paths.tmp))
      .pipe(safeJade)
      .pipe(through2.obj(function(file, encoding, next) {
        // Fake path for wiredep
        file.path = path.join(__dirname, paths.src, 'index.html');
        file.base = path.dirname(file.path);
        next(null, file);
      }))
      .pipe(wiredep({directory: 'app/bower_components', exclude: [/jquery/, /js\/bootstrap/]}))
      .pipe(gulp.dest(paths.tmp))
      .pipe(connect.reload())
  );

});

The first streams is never completed but killed halfway (only one jade view gets processed). Any ideas?


EDIT: found out that var safeJade = combine(jade({pretty: true})); is the culprit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

gulp.js - How do I return multiple streams back to main stream?
You can concatenate streams with merge-stream var gulp = require('gulp'); var merge = require('merge-stream'); gulp.task('bundle', ...
Read more >
How to synchronize a Gulp-task that starts multiple streams in ...
The function incDoneCounter() is called at the end of every stream. It increments the variable doneCounter . If all streams have finished ...
Read more >
gulp API docs
Returns a stream of Vinyl files that can be piped to plugins. ... gulp supports all options supported by node-glob and glob-stream except...
Read more >
Working with Files | gulp.js
The stream produced by src() should be returned from a task to signal async completion, as mentioned in Creating Tasks. const { src,...
Read more >
Browsersync + Gulp.js
Streams are supported in Browsersync, so you can call reload at specific ... sass into CSS & auto-inject into browsers gulp.task('sass', function() {...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found