Permalink
Browse files

fix to pause the dnode stream

  • Loading branch information...
substack committed Sep 28, 2012
1 parent 82f7251 commit 3e3019f5a7a8578c960ec4f0ef4ac7564e3c9fe9
Showing with 28 additions and 11 deletions.
  1. +14 −5 example/freestyle/43_server.js
  2. +14 −6 example/freestyle/44_server.js
@@ -6,25 +6,34 @@ var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter;
var dnode = require('dnode');
+var pauseStream = require('pause-stream');
function createStream () {
var MuxDemux = require('mux-demux');
var mdm = new MuxDemux;
var ms = model.createStream();
var es = emitStream(emitter);
-
- mdm.on('connection', function (c) {
- c.pipe({ state : ms, events : es }[c.meta]).pipe(c);
- });
-
var d = dnode({
loud : function (s, cb) { cb(s.toUpperCase) });
});
+ var dps = d.pipe(pauseStream());
+ dps.pause();
+
+ mdm.on('connection', function (c) {
+ c.pipe({
+ state : ms,
+ events : es,
+ dnode : dps
+ }[c.meta]).pipe(c);
+ });
process.nextTick(function () {
ms.pipe(mdm.createStream('state')).pipe(ms);
es.pipe(mdm.createStream('events')).pipe(es);
+
+ dps.pipe(mdm.createStream('dnode')).pipe(dps);
+ dps.resume();
model.set('connections', (model.get('connections') || 0) + 1);
});
@@ -6,26 +6,34 @@ var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter;
var dnode = require('dnode');
+var pauseStream = require('pause-stream');
function createStream () {
var MuxDemux = require('mux-demux');
var mdm = new MuxDemux;
var ms = model.createStream();
var es = emitStream(emitter);
+ var d = dnode({
+ loud : function (s, cb) { cb(s.toUpperCase()) }
+ });
+ var dps = d.pipe(pauseStream());
+ dps.pause();
mdm.on('connection', function (c) {
- c.pipe({ state : ms, events : es }[c.meta]).pipe(c);
+ c.pipe({
+ state : ms,
+ events : es,
+ dnode : d
+ }[c.meta]).pipe(c);
});
process.nextTick(function () {
- var d = dnode({
- loud : function (s, cb) { cb(s.toUpperCase()) }
- });
- d.pipe(mdm.createStream('dnode')).pipe(d);
-
ms.pipe(mdm.createStream('state')).pipe(ms);
es.pipe(mdm.createStream('events')).pipe(es);
+
+ dps.pipe(mdm.createStream('dnode')).pipe(d);
+ dps.resume();
model.set('connections', (model.get('connections') || 0) + 1);
});

0 comments on commit 3e3019f

Please sign in to comment.