Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

error submission #10

Merged
merged 1 commit into from

2 participants

@Raynos

No description provided.

@dominictarr dominictarr merged commit 05276aa into dominictarr:master
@dominictarr
Owner

thanks, this is great. it's in mux-demux@2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 14, 2012
  1. @Raynos

    error submission

    Raynos authored
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 0 deletions.
  1. +28 −0 examples/error.js
  2. +5 −0 index.js
View
28 examples/error.js
@@ -0,0 +1,28 @@
+var MuxDemux = require('..')
+var net = require('net')
+
+net.createServer(function (con) {
+
+ var mdm2 = MuxDemux()
+ mdm2.on('connection', function (stream) {
+ stream.on('error', function (error) {
+ console.log(error.message)
+ })
+ })
+ con.pipe(mdm2).pipe(con)
+
+}).listen(8642, function () {
+
+ var mdm1 = MuxDemux()
+ var con = net.connect(8642)
+ con.pipe(mdm1).pipe(con)
+ var es = mdm1.createWriteStream('errors')
+
+ setInterval(function () {
+ es.error("error message as string")
+ }, 1e3)
+
+})
+
+
+
View
5 index.js
@@ -30,6 +30,8 @@ function MuxDemux (opts) {
s.paused = false
if(p) s.emit('drain')
}
+ else if (event === 'error')
+ s.emit('error', new Error(data[1]))
else {
s.emit.apply(s, data)
}
@@ -76,6 +78,9 @@ function MuxDemux (opts) {
s.resume = function () {
md.emit('data', [s.id, 'resume'])
}
+ s.error = function (message) {
+ md.emit('data', [s.id, 'error', message])
+ }
s.once('close', function () {
md.emit('data', [s.id, 'close'])
delete streams[id]
Something went wrong with that request. Please try again.