Closed mcollina closed 5 years ago
The handling of (_)destroy
, destroyed
and _finish
vs _final
should be updated.
For destroy
, it might suffice to simply remove the following:
https://github.com/mafintosh/duplexify/blob/683ee893bb34202d1f00228e184ca38dfb849d50/index.js#L57
https://github.com/mafintosh/duplexify/blob/683ee893bb34202d1f00228e184ca38dfb849d50/index.js#L199
@vweevers I've updated destroy, but I don't know what you mean with _final
vs _finish
change.
I don't know what you mean with _final vs _finish change
I think the _finish
method here is custom logic for delaying the finish
event, using the undocumented prefinish
event and _writableState.prefinished
. We now have _final
for this use case.
@vweevers done!
Looks OK to me! Can't say I fully understand the internals though. What's the purpose of ondrain
, and why is it called in _destroy
?
ondrain is a user specified function.
ondrain is a user specified function.
There's this too:
https://github.com/mafintosh/duplexify/blob/09f469620d31c97153f3f5194154f755294854bd/index.js#L194
I’ll take a look, it might not be needed after all.
ondrain was not really needed in _destroy(), it' all handled by _destroy now.
@mafintosh did you mean to bump the version of readable-stream
in master without these changes here?
We're seeing stack traces with the latest duplexify
release which is required by @google-cloud/pubsub
Error: Cannot call write after a stream was destroyed
at doWrite (/src/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:405:38)
at writeOrBuffer (/src/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:394:5)
at Duplexify.Writable.write (/src/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:303:11)
at Duplexify.end (/src/node_modules/duplexify/index.js:230:41)
at Immediate.onConnectionStatus (/src/node_modules/@google-cloud/pubsub/src/connection-pool.js:275:18)
at runCallback (timers.js:706:11)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:121:23)
@hxtomprice hmm, let me take a look
@hxtomprice master should work fine, i can't see where dupelxify is used in that repo. you have a link?
Gonna revert the one in master and move it to a new major instead to be safe. My guess is that it's a timing change as the destroy semantics are more rigourous now.
@mafintosh Do you have the intention of merging this later on? Maybe it wouldn't make a functional difference, but it does serve an educational purpose. Personally I learned more about streams from reading the source code of modules like this, than from reading streams core (with its complicated state). I think it'd benefit the community if modules use patterns like _destroy
and _final
as much as possible, to advocate best practices, advertise the abilities of streams, make code easier to understand for beginners and ultimately lead to a more homogeneous ecosystem. Thoughts?
As titled.
This is semver-major.
It would be good if it included https://github.com/maxogden/concat-stream/pull/61, but that's only a dev dependency, so it can land otherwise.