Skip to content

Instantly share code, notes, and snippets.

@stephenplusplus
Created February 5, 2015 20:36
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 stephenplusplus/fdd874987fc090b43e16 to your computer and use it in GitHub Desktop.
Save stephenplusplus/fdd874987fc090b43e16 to your computer and use it in GitHub Desktop.
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
}
@stephenplusplus
Copy link
Author

$ node ./
source stream [Error: read failed]
dest stream [Error: write failed]

@ryanseys
Copy link

ryanseys commented Feb 5, 2015

:(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment