Skip to content

Instantly share code, notes, and snippets.

@kbshl
Created September 16, 2014 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbshl/b7e73cb30f37718a394e to your computer and use it in GitHub Desktop.
Save kbshl/b7e73cb30f37718a394e to your computer and use it in GitHub Desktop.
Gulp Receipe: Combining streams to handle errors
// Combining streams to handle errors
// By default, emitting an error on a stream will cause it to be thrown unless it already has a listener attached to the error event. This gets a bit tricky when you're working with longer pipelines of streams.
// By using multistream you can turn a series of streams into a single stream, meaning you only need to listen to the error event in one place in your code.
// Here's an example of using it in a gulpfile:
var Multistream = require('multistream');
var uglify = require('gulp-uglify');
var gulp = require('gulp');
gulp.task('test', function() {
var combined = Multistream([
gulp.src('bootstrap/js/*.js'),
uglify(),
gulp.dest('public/bootstrap')
]);
// any errors in the above streams will get caught
// by this listener, instead of being thrown:
combined.on('error', console.error.bind(console));
return combined;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment