Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions docs/recipes/combining-streams-to-handle-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@ 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 [gulp-util](https://github.com/gulpjs/gulp-util)'s `combine`
method you can turn a series of streams into a single stream, meaning you
By using [lazypipe](https://github.com/OverZealous/lazypipe) 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:

``` javascript
var combine = require('gulp-util').combine
var uglify = require('gulp-uglify')
var gulp = require('gulp')
var lazypipe = require('lazypipe'),
uglify = require('gulp-uglify'),
gulp = require('gulp');

gulp.task('test', function() {
var combined = combine(
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', function(err) {
console.warn(err.message)
})

return combined
})
// Once the partial pipeline is ready to use,
// call the last result from .pipe() directly as a function
var combined = lazypipe()
.pipe(uglify)
.pipe(gulp.dest, 'public/bootstrap')();

gulp.src('bootstrap/js/*.js').pipe(combined);

// any errors in the above streams
// will get caught by this listener,
// instead of being thrown:
combined.on('error', function(err) {
console.warn(err.message);
});

return combined;
});
```

You can use this technique in your gulp plugins and node modules too using
Expand Down