Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Dont error #3

Merged
merged 4 commits into from

2 participants

@Raynos

No description provided.

@dominictarr dominictarr merged commit abf7ad8 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 4, 2012
  1. @Raynos

    turn errors off

    Raynos authored
  2. @Raynos

    whitespace ._.

    Raynos authored
  3. @Raynos

    tap in dev dependencies

    Raynos authored
  4. @Raynos

    docs

    Raynos authored
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 12 deletions.
  1. +15 −11 index.js
  2. +2 −1  package.json
  3. +10 −0 readme.markdown
View
26 index.js
@@ -1,6 +1,6 @@
var es = require('event-stream')
-function MuxDemux (name) {
+function MuxDemux (opts) {
function createID() {
return (
@@ -32,14 +32,18 @@ function MuxDemux (name) {
})
function destroyAll (_err) {
- md.removeListener('end', destroyAll)
- md.removeListener('error', destroyAll)
- md.removeListener('close', destroyAll)
+ md.removeListener('end', destroyAll)
+ md.removeListener('error', destroyAll)
+ md.removeListener('close', destroyAll)
var err = _err || new Error ('unexpected disconnection')
for (var i in streams) {
var s = streams[i]
- s.emit('error', err)
- s.destroy()
+ if (opts && opts.error === false) {
+ s.end()
+ } else {
+ s.emit('error', err)
+ s.destroy()
+ }
}
}
@@ -57,14 +61,14 @@ function MuxDemux (name) {
throw new Error('stream is not writable')
md.emit('data', [s.id, 'data', data])
}, function () {
- md.emit('data', [s.id, 'end'])
+ md.emit('data', [s.id, 'end'])
})
s.pause = function () {
md.emit('data', [s.id, 'pause'])
}
s.resume = function () {
md.emit('data', [s.id, 'resume'])
- }
+ }
s.once('close', function () {
md.emit('data', [s.id, 'close'])
delete streams[id]
@@ -73,7 +77,7 @@ function MuxDemux (name) {
s.readable = opts.readable
streams[s.id = id] = s
s.meta = meta
- return s
+ return s
}
var outer = es.connect(es.split(), es.parse(), md, es.stringify())
@@ -88,7 +92,7 @@ function MuxDemux (name) {
pipe.call(outer, dest, opts)
md.on('end', destroyAll)
md.on('close', destroyAll)
- md.on('error', destroyAll)
+ md.on('error', destroyAll)
return dest
}
@@ -96,7 +100,7 @@ function MuxDemux (name) {
opts = opts || {writable: true, readable: true}
var s = createStream(createID(), meta, opts)
var _opts = {writable: opts.readable, readable: opts.writable}
- md.emit('data', [s.id, 'new', {meta: meta, opts: _opts}])
+ md.emit('data', [s.id, 'new', {meta: meta, opts: _opts}])
return s
}
outer.createWriteStream = function (meta) {
View
3  package.json
@@ -14,7 +14,8 @@
"test": "tap test/*.js"
},
"devDependencies": {
- "assertions": "2.3"
+ "assertions": "2.3",
+ "tap": "~0.3.0"
},
"author": "Dominic Tarr <dominic.tarr@gmail.com> (dominictarr.com)",
"optionalDependencies": {},
View
10 readme.markdown
@@ -53,6 +53,16 @@ client.createStream(meta)
there is actually no distinction between clients and servers.
if both sides are listening `on('connection',...)` then both sides may call `create{Write,Read,}Stream(meta)` and initiate new streams.
+### MuxDemux(options)
+
+Creates a MuxDemux stream. Optionally pass in an options hash
+
+ {
+ error: Boolean
+ }
+
+If the error option is set to false then MuxDemux won't emit errors on the streams on unexpected disconnects and instead just end those streams
+
### createReadStream (meta)
open a `ReadableStream` from the other side.
Something went wrong with that request. Please try again.