Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[streams] _flush not being called #53

Closed
missinglink opened this issue Dec 4, 2014 · 4 comments
Closed

[streams] _flush not being called #53

missinglink opened this issue Dec 4, 2014 · 4 comments
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@missinglink
Copy link
Contributor

In the following testcase the _flush callback is not being called after stream.end().

Simply removing the stream.write(null); line works fine.

Is it possible to end a stream with stream.write(null) and stream.end() or only the latter.

If so, why does stream.write(null) prevent stream.end() from triggering _flush?

var Transform = require('readable-stream/transform'),
    inherits  = require('util').inherits;

function MyTransform(opts){
  Transform.call(this, opts);
}

inherits(MyTransform, Transform);

MyTransform.prototype._transform = function( chunk, enc, next ){
  console.log('.');
  next();
};

MyTransform.prototype._flush = function(){
  console.log('END');
};

// ---

var stream = new MyTransform({ objectMode: true });

stream.write({ a: 'b' });
stream.write(null);
stream.end();

same behaviour on v0.11.14 and v0.10.33

ref: #89

@missinglink
Copy link
Contributor Author

@rvagg, @isaacs I'm happy to look in to this and submit a PR.

Can you please confirm that sending stream.write(undefined), stream.write(null) and calling stream.end() should all end a Transform stream in the same way?

Is this the same behaviour for objectMode:true and objectMode:false?

ref: https://github.com/isaacs/readable-stream/blob/master/test/simple/test-stream2-transform.js#L453

@chrisdickinson
Copy link
Contributor

Can you please confirm that sending stream.write(undefined), stream.write(null) and calling stream.end() should all end a Transform stream in the same way?

stream.write(null | undefined) should not end a stream -- the null EOF is only triggered through the readable's internal_-ish_ .push method.

It's down to this line -- specifically the isNull check. This sits at a weird place on the "bug or normal behavior" spectrum: without the check, all of the tests still pass, and in objectMode one would expect any value written to the stream to be transformed, but as it stands, in most cases null is an "out of alphabet" value for streams and represents the end of a stream.

(Tangentially, I'd love to move away from null-as-EOF in the future for this (and other) reasons.)

@sonewman
Copy link
Contributor

I agree since it always feels weird to me calling .push(null) when ending a readable stream.

@vkurchatkin vkurchatkin added the stream Issues and PRs related to the stream subsystem. label Jan 23, 2015
@Qard
Copy link
Member

Qard commented Aug 14, 2015

I'm closing this as the question was answered and there doesn't appear to be anything else immediately actionable here. Please feel free to re-open it if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

7 participants