diff --git a/lib/lazystream.js b/lib/lazystream.js index 09587b1..d9f6170 100644 --- a/lib/lazystream.js +++ b/lib/lazystream.js @@ -1,6 +1,5 @@ - var util = require('util'); -var PassThrough = require('stream').PassThrough || require('readable-stream/passthrough'); +var PassThrough = require('readable-stream/passthrough'); module.exports = { Readable: Readable, @@ -29,10 +28,8 @@ function Readable(fn, options) { beforeFirstCall(this, '_read', function() { var source = fn.call(this, options); - var that = this - source.on('error', function(err) { - that.emit('error', err) - }) + var emit = this.emit.bind(this, 'error'); + source.on('error', emit); source.pipe(this); }); @@ -47,10 +44,8 @@ function Writable(fn, options) { beforeFirstCall(this, '_write', function() { var destination = fn.call(this, options); - var that = this - destination.on('error', function(err) { - that.emit('error', err) - }) + var emit = this.emit.bind(this, 'error'); + destination.on('error', emit); this.pipe(destination); });