-
Notifications
You must be signed in to change notification settings - Fork 164
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
What should we call ReadableByteStream.prototype.getBYOBReader()? #294
Comments
Naming after reader's type name looks natural to me. |
Well, but do you have an idea for the reader's type name? :) |
[Readable]BytesStreamReader and getBytesReader, perhaps? |
Yeah that kind of works, since it's about specialized behavior for byte streams. But then again, |
What about inverting it, such that |
@chrisdickinson that's not as good, I think, because ideally |
In offline discussion last Thursday, we categorized the readers we've been designing using a matrix.
(BYOB && Auto pull) doesn't make sense. So, it's marked We're going to at least provide factory methods for A, B. The "Alloc: auto" row also applies to object streams. Both of B and C make sense. I think C means that pulling one element. For byte streams, I realized that I don't know what we should do for C well. C is manual pull. We're going to pull some bytes. How many? The user needs to call So, if A, B and C make sense for byte streams, and B and C make sense to object streams, how should we organize the factory methods?
Gave verbose names for the first step. |
Yeah, exactly. This would probably be done intelligently on a per-stream basis. IIRC libuv has heuristics for this (since Node streams are not BYOB), @piscisaureus mentioned them to me once. It also says, "I don't care about reusing buffers, and will let the JavaScript GC take care of freeing the memory". I am starting to think that an options-object accepting
Or maybe we want the default to be auto-pulling, so instead of
The interesting thing about object streams B vs. C is that previously we kind of let this be controlled by the strategy instead of by the consumer. (Although even then I think we always would be trying to pull at least some before exerting backpressure.) We could move that all to configuration to getReader? Wait, but how does C work for object streams that are wrapping push sources? I think the |
Upon further reflection I am not sure auto-pulling vs. manual-pulling is a property of the reader. It may be more of a property of the stream. If it is a property of the reader, you should be able to get an auto-pulling reader, then release it and get a manual-pulling one. Or vice versa. That seems strange and potentially hard to implement. |
OK. Maybe "auto-pull" concept doesn't make sense when discussing a reader interface. What's going on behind a reader is unknown and abstracted. We basically shouldn't mention about anything behind it when naming the methods. Pulling vs. non-pulling (give me when available) is the right way of comparison? |
Tentative plan per afternoon discussions:
|
@tyoshino I am coming back to this issue several months later and it seems we kind of forgot about a lot of the ideas in #294 (comment). Given how our thinking has evolved, e.g. in #329 and #361, what are your thoughts on that comment? |
Thanks for reminder, Domenic. I'd like to begin with responding to #294 (comment)
This is still true, I think. Less methods sounds better basically. E.g. if we decide to implement various readers as I listed in #329 (comment), the option takes
I'm gonna investigate if I can integrate the strategy mechanism with the up-to-date RBS (has pull/pullInto) well.
BYOB of the up-to-date RBS should just work (though involves copy). |
I have spun off a lot of that stuff into #375. That leaves this thread for its original purpose, bikeshedding the name :). So you think it should be
The other alternative we were thinking was rbs.getReader({ feedBuffers: true });
rbs.getReader({ feedBuffers: false });
rbs.getReader(); // equivalent to false but I think that you are right that future expansion is better served by a string enum. |
Ah, good point. Yeah, explicit parameters (boolean) for each feature is cleaner, but with mode string we can list only meaningful combinations and maybe robust for future extensions. |
ReadableByteStream has been merged into ReadableStream (#379). Now ReadableStream has both getReader and getBYOBReader(). It's time to resume discussion on this issue and finalize the BYOB API surface. |
I think your arguments for |
Reviewed the discussion in this thread. Yes, I still like the plan to add options to getReader(). Regarding the name, I think "buffer-provided" and "buffer-fed" are the candidates I'm still considering in addition to "byob".
BTW, the differentiation between "auto pull" and "manual pull" discussed around #294 (comment) has been well depicted in the new examples written by Domenic. #430 (comment) is also related. In the latest spec, we chose to have the controllers expose queuing status via the |
Now I feel that So, I propose:
|
Hmm. I still like keeping BYOB in those names, because BYOB is the new capability on top of the default. I think it would be OK to keep it. I think of the Among byob, buffer-fed, and buffer-provided I think byob is pretty good. Maybe it is just because we have been staring at that for a few months though. I think buffer-fed is better than buffer-provided probably. |
In addition to #294 (comment), I'm thinking about the case in which we need to introduce the read() with ack functionality. If we introduce the feature, we would need to also add a new interface to the controller. Then, the controller will gain one more new feature in addition to BYOB. Considering such possibility, I was leaning toward giving more general name to it. Of course, we could just add a new controller. WDYT?
OK. Let's go in "byob". |
Hmm, it is hard to say. Whether we introduce a new controller or not would depend on how different the internal state tracking would be. I guess I see two options:
I am OK with either. So the total changes being contemplated here are:
But no renaming for ReadableStreamBYOBReader or ReadableStreamBYOBRequest or for the underlying source option ( |
Thanks.
Yeah. I can't come up with estimation of the complexity it would add for now.
I see.
Yes!
I thought that if we rename ReadableStreamBYOBController, the underlying source option should also be renamed as it's an option telling what type of controller it needs or what set of reading operations the stream should expose. But yeah, we could just add a new parameter say "bufferLeasing: true" in addition to byob. So, ok. |
Hmm, I see. I think the real question is: do we expect a 1:1:1 underlying source types <-> controller types <-> reader types. I guess we should not necessarily expect that. Right now we have 1:1 underlying source types <-> controller types, and that will probably stay forever. But the correspondence with reader types is already not 1:1 since you can get both default and byob readers from (what is currently called) a ReadableStreamBYOBController. So, OK. We should reflect this asymmetry in the API. New plan:
(Maybe there is a better word than |
Yeah, in the last comment of mine, I thought we could have the ReadableStream constructor parameters each corresponds to enabled getReader() mode, but I prefer your idea. Yes, 1:1 correspondence between underlying source types and controller types should be stable for long time. Please review the PR. |
Instead of `byob: true`, it's now `type: "bytes"`. Partially fixes #294.
Per the lengthy discussions in #253 the new shape of ReadableByteStream will be something like:
getReader()
returns a reader that, much like the "normal" ReadableStream, has automatically flowing auto-allocated chunks. So,rbs.getReader().read()
will take no arguments and will auto-allocate a newUint8Array
each call.getBYOBReader()
, returns a reader that requires you to feed it buffers. So, you callrbs.getBYOBReader().read(myBuffer)
and it reads intomyBuffer
. (After doing appropriate detaching/transferring to ensure no observable data races, etc., as discussed extensively in Support reading bytes into buffers allocated by user code on platforms where only async read is available #253 and elsewhere.)Here "BYOB" stands for "bring your own buffer," by the way.
Ideas for names:
getBYOBReader()
getManualReader()
getBufferedReader()
getFedReader()
getManualFeedReader()
getControlledAllocationReader()
getReadIntoReader()
getBytesReader()
(although the normal reader also gives you bytes)getPullingReader()
(referring to how generally no reading is done until you callread(view)
, i.e. data is "pulled")getReader({ feedBuffers: true })
or similar (introduces some kinda-strange return type variance though)Are there any precedents from other platforms we can draw on, just for vocabulary if nothing else?
The text was updated successfully, but these errors were encountered: