Created
February 5, 2015 20:36
-
-
Save stephenplusplus/fdd874987fc090b43e16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stream = require("stream") | |
getSourceStreamThatThrowsError(). | |
on("error", console.error.bind(null, "source stream")). | |
pipe(getDestinationStreamThatThrowsError()). | |
on("error", console.error.bind(null, "dest stream")) | |
function getSourceStreamThatThrowsError() { | |
var rs = new stream.Readable | |
var readCount = 0 | |
rs._read = function () { | |
readCount++ | |
this.push(String(readCount)) | |
if (readCount == 3) { | |
this.push(null) | |
this.emit("error", new Error("read failed")) | |
} | |
} | |
return rs | |
} | |
function getDestinationStreamThatThrowsError() { | |
var fs = new stream.Writable | |
var writtenCount = 0 | |
fs._write = function (chunk, enc, next) { | |
writtenCount++ | |
if (writtenCount == 2) { | |
this.emit("error", new Error("write failed")) | |
this.end() | |
} | |
next() | |
} | |
return fs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment