-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
stream: implement WritableBase without buffering #33515
Conversation
This is very much WIP but I would like some initial feedback whether this is worth further engagement. |
@nodejs/streams |
lib/_stream_writable.js
Outdated
ObjectSetPrototypeOf(Writable.prototype, Stream.prototype); | ||
ObjectSetPrototypeOf(Writable, Stream); | ||
const kFlush = Symbol('kFlush'); | ||
class WritableState extends WritableBase.WritableState { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extends WritableBase.WritableState
Might also be useful for the QUIC work. |
I really like the direction this is going, however I would prefer to land this together with the changes in the other places it is targeting. I suspect you want to try making |
Good. I just wanted to make sure this is worth spending more time on. I'll start with |
(Keep them on separate commits, so that we can easily split it up if we need to for ease of backporting). |
8ae28ff
to
2935f72
Compare
c83723e
to
a3fdb90
Compare
@mcollina: This kind of works now... Still has some details I would like to improve upon. However, when trying to use it to implement
Maybe @jasnell would have use of this for quic... not sure where to take it from here. Maybe put on ice for now? |
Given all the above, I would put on ice. Unless @jasnell (or somebody else) has a good use for this. |
This separates the
Writable
class into two classes aWritableBase
class which implements allWritable
logic except for anything related to buffering, and aWritable
class which inheritsWritableBase
and adds the buffering logic.This is in order to be able to consistently and in a performant way implement
Writable
streams that want to implement their own buffering or are simply wrapping existing streams.WritableBase
expects 2 methods passed throughoptions
:write
: which is basically thewriteOrBuffer
implementation from today.flush
: which is basicallyend()
+ wait for completion from today.Note, that this is for now only for internal core usage not meant for public API.
This will help with making
Writable
like implementations where we want to avoid buffering or sequential writes more streams compliant, e.g.OutgoingMessage
.It will also help with some optimization e.g. avoid buffering both input and output of
Transform
stream by implementing it in terms ofReadable
+WritableBase
instead ofReadable
+Writable
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes