end(data) doesn't seem to fire the 'data' event #1

Open
coryvirok opened this Issue Nov 28, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@coryvirok

I just started looking into your event-stream library and it looks pretty awesome... I ran into this though.

var eventstream = require('event-stream');

var theData;
var endEmitted = false;
var ws = eventstream.map(function(data, callback) {
  return callback(null, data);
});

ws.on('data', function(data) {
  theData = data;
});
ws.on('end', function(err) {
  endEmitted = true;
});

function check() {
  if (endEmitted) {
    console.log('end emitted, theData: %s', theData);
  } else {
    setTimeout(check, 1000);
  }
};

setTimeout(check, 1000);

ws.end('OH HAI');

outputs:

end emitted, theData: undefined

If I change it to use

ws.write('OH HAI');
ws.end();

we get

end emitted, theData: OH HAI
@dominictarr

This comment has been minimized.

Show comment Hide comment
@dominictarr

dominictarr Nov 28, 2012

Owner

you don't need a timeout to check this, 'data' should always emit strictly before 'end'.
that said, end(data) isn't strictly a part of Streams, it's a convenience api.

I'll merge a pull request if you make one, else use ws.write(data)

Owner

dominictarr commented Nov 28, 2012

you don't need a timeout to check this, 'data' should always emit strictly before 'end'.
that said, end(data) isn't strictly a part of Streams, it's a convenience api.

I'll merge a pull request if you make one, else use ws.write(data)

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