Vitali Zaidman
Vitali Zaidman

Reputation: 948

Gulp sequence for streams

So I have stream1 who writes to dest and I have stream2 who in it's process reads the written file from stream1.

How do I manage to run them in sequence.

There's gulp-sequence but I need to run streams in sequence in one task and not tasks in sequence.

Upvotes: 1

Views: 409

Answers (1)

Vitali Zaidman
Vitali Zaidman

Reputation: 948

OK so i've written a code of my own to do it, you are welcome to create a plugin out of it, and also improve it. enjoy:

var es = require('event-stream');
function sequance(streams){
  var ps = es.pause();
  ps.pause();

  (function runStream(i){
    if(i >= streams.length){
      ps.resume();
      return;
    }
    var stream = streams[i];
    stream = _.isFunction(stream) ? stream() : stream;
    stream.on('end', function(){
      runStream(i + 1);
    });
  })(0);

  return ps;
}

Upvotes: 1

Related Questions