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

Add ReadableByteStream definition #343

Closed
wants to merge 13 commits into from
Closed

Conversation

tyoshino
Copy link
Member

No description provided.

@tyoshino
Copy link
Member Author

WIP

@domenic
Copy link
Member

domenic commented Apr 22, 2015

https://streams.spec.whatwg.org/branch-snapshots/readablebytestreamspec/ for preview. Has some minor errors. I will push an extra commit to fix those (but won't force-push in case you have work locally).

@domenic
Copy link
Member

domenic commented Apr 22, 2015

In terms of the MVP for helping MSE, I think we want:

  • Complete class definitions
  • AcquireReadableByteStreamReader(rbs) and ReadFromReadableByteStreamReader(reader, destView)
  • The text sections filled in ("Readable Byte Streams" and "Using Readable Byte Streams").

I think it'd also be ideal to not have any known-inaccurate algorithms, and for the ones we're unsure on have a warning <div>.

- Mention readable byte stream reader in Locking section
- Don't mention Writable Byte Stream for now
- Add a short introduction text about readable byte stream
- Fit 120 col
- Don't mention BYOB reader for now
- Refer to readable stream about pipeTo
- Rename fulfill() to resolve()
- Rename FinishClosingReadableByteStream to CloseReadableByteStream
- Add TeeReadableByteStream algorithm
- Add new ReadableByteStream algorithm
@tyoshino
Copy link
Member Author

Thanks for the advice. I've pushed one more commit. Yes, I found that dfn was missing for underlying byte stream but couldn't push the fixed one yesterday.

I tried to define ReadableByteStream without the default built-in queue. If it turns out to be not promising, I'll just revert them to just refer to ReadableStream's algorithms.

BTW, when I run ecmarkupify, npm complains like "... node_modules/ecmarkupify/package.json not found". Do you have any ideas what's happening?

@domenic
Copy link
Member

domenic commented Apr 23, 2015

BTW, when I run ecmarkupify, npm complains like "... node_modules/ecmarkupify/package.json not found". Do you have any ideas what's happening?

The only thing I can think of is make sure you are on a recent io.js and then do rm -rf node_modules && npm install. This should be done in the root, not in reference_implementation (which is a separate package).

@tyoshino
Copy link
Member Author

Thanks! I didn't know I needed io.js. It works now.

@tyoshino
Copy link
Member Author

Ready for review. This PR should also satisfy #312.

@domenic
Copy link
Member

domenic commented Apr 30, 2015

Will try to do review tonight or tomorrow morning.

What are your thoughts on a reference implementation/tests?


<h3 id="rbs-intro">Using Readable Byte Streams</h3>

<div class="example">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These informative sections don't seem quite complete. But, I can try my hand at expanding them.

@domenic
Copy link
Member

domenic commented Apr 30, 2015

OK, I guess I couldn't resist at least a high-level review.

I am a bit confused by the controller + underlying source model here. From what I can see, the idea is that pull() is called on each read, and each time it is called, you can call c.resolve(chunk) once. Is that the idea?

I thought though that ReadableByteStream was going to need an internal queue as well. Because what if someone doesn't read for a long time, and the kernel buffer starts getting full? Do we make underlying byte source implementers do their own buffering to handle that case?

Also I know we had a discussion in person which concluded that c.resolve(chunk) was better than return chunk or return promiseForChunk, mainly having to do with cancelation. Can you help remind me why that was important?

The resolve name is probably not the best but we can figure it out later. (Maybe it is fine but it feels like it's too tied to promise terminology, whereas promises are kind of more an implementation detail, that the underlying byte source should not need to know about.)

1. Set _reader_@[[ownerReadableByteStream]] to *undefined*.
</pre>

<h4 id="tee-readable-byte-stream" aoid="TeeReadableByteStream">TeeReadableByteStream ( stream, shouldClone )</h4>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is complicated. With the queues and such. Could you summarize for me how it works? It looks similar to TeeReadableStream but I am betting there are important differences.

@tyoshino tyoshino mentioned this pull request May 1, 2015
@tyoshino
Copy link
Member Author

tyoshino commented May 1, 2015

I am a bit confused by the controller + underlying source model here. From what I can see, the idea is that pull() is called on each read, and each time it is called, you can call c.resolve(chunk) once. Is that the idea?

Right. pull() is just a notification of read(). The user can call c.resolve(chunk) at any time.

The readable byte stream is kept as minimum as possible but able to represent invariants, constraints, semantics of the API surface completely. The controller is not designed considering usability. Maybe, I should not have added the controller API but only define abstract operations to manipulate the readable byte stream's state.

I thought though that ReadableByteStream was going to need an internal queue as well. Because what if someone doesn't read for a long time, and the kernel buffer starts getting full? Do we make underlying byte source implementers do their own buffering to handle that case?

The latter.

Also I know we had a discussion in person which concluded that c.resolve(chunk) was better than return chunk or return promiseForChunk, mainly having to do with cancelation. Can you help remind me why that was important?

You were imagining some example implementation of the underlying source where you're trying to encapsulate an async API that returns a promise. And you said that we basically want to return the promise (as-is or after some transform) than converting it to call to c.resolve(), etc.

The resolve name is probably not the best but we can figure it out later. (Maybe it is fine but it feels like it's too tied to promise terminology, whereas promises are kind of more an implementation detail, that the underlying byte source should not need to know about.)

Was using fulfill. Fulfill might be better as the streams are supposed to be enqueued non-promise values?

@domenic
Copy link
Member

domenic commented May 1, 2015

The readable byte stream is kept as minimum as possible but able to represent invariants, constraints, semantics of the API surface completely. The controller is not designed considering usability. Maybe, I should not have added the controller API but only define abstract operations to manipulate the readable byte stream's state.

I see. So we may want to make it clear that this is still undergoing revision. But the public API will be OK.

Do we make underlying byte source implementers do their own buffering to handle that case?

The latter.

This seems sad. Also I think we wanted to support buffering (in the non-BYOB case) to avoid "jitter"? Hmm.

You were imagining some example implementation of the underlying source where you're trying to encapsulate an async API that returns a promise. And you said that we basically want to return the promise (as-is or after some transform) than converting it to call to c.resolve(), etc.

Right, I remember the argument for using promises instead of c.resolve :). But I forget the argument for using c.resolve instead of promises. Sorry, I guess I was a bit unclear what my question was there.

Was using fulfill. Fulfill might be better as the streams are supposed to be enqueued non-promise values?

I meant more pick a verb that has nothing to do with promises. Looking through a thesaurus, here are some random options: answer, conclude, fill, finish, satisfy, produce, complete, finalize, respond.


Anyway, let's start merging stuff and iterating on it in further PRs and issues, using #300 as the central tracking issue once the dust settles. I think we should squash everything into a single commit that does the following:

If this sounds good to you, let me know. If you are ready to go to sleep then I will do it (and file a few follow-up issues/PRs). Or if you want to take care of some other stuff first before we merge, or you want to work on the squashed commit yourself, then that's good too :).

@tyoshino
Copy link
Member Author

tyoshino commented May 1, 2015

Right, I remember the argument for using promises instead of c.resolve :). But I forget the argument for using c.resolve instead of promises. Sorry, I guess I was a bit unclear what my question was there.

IIRC, it was something like race between:

  • the stream getting updated by the fulfillment/rejection callback set to the returned promise
  • controller.close()

We were drawing timeline on a whiteboard to discuss this.

@domenic
Copy link
Member

domenic commented May 1, 2015

Yeah. I just wish we had captured it somewhere digital, haha.

@tyoshino
Copy link
Member Author

tyoshino commented May 1, 2015

If you are ready to go to sleep then I will do it (and file a few follow-up issues/PRs).

Thanks. I'm adding BYOB stuff in local copy but that doesn't block the work. I'm still in the office but wouldn't get time to do squashing, etc. before last train.

So, please :)

@domenic
Copy link
Member

domenic commented May 3, 2015

Merged as 5b47faa per plan at #343 (comment).

@domenic domenic closed this May 3, 2015
@tyoshino tyoshino deleted the readablebytestreamspec branch May 7, 2015 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants