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

streamsapi.js externs: Sink / Source types too strict? #2108

Open
ricea opened this issue Oct 27, 2016 · 2 comments
Open

streamsapi.js externs: Sink / Source types too strict? #2108

ricea opened this issue Oct 27, 2016 · 2 comments

Comments

@ricea
Copy link
Member

ricea commented Oct 27, 2016

All the Promise-returning methods for ReadableStreamSource and ReadableStreamSink can actually return thenables.

This means that, for example, the return type specified here is too strict:

/** @type {(undefined|function(*):(!Promise<*>|undefined))} */
ReadableStreamSource.prototype.cancel;

I haven't actually had a real problem with this, I just work on the Streams standard. It may well be that there's no need to make this requirement more relaxed.

@vobruba-martin
Copy link
Contributor

Spec doesn't say anything about thenables. Or am I missing something here? https://streams.spec.whatwg.org/

@ricea
Copy link
Member Author

ricea commented Oct 28, 2016

It doesn't mention it explicitly. I brought this up in whatwg/streams#566 and it doesn't seem it's going to be made explicit. You need to follow the algorithms to find out what the exact semantics are. For example, the cancel method is called at https://streams.spec.whatwg.org/#rs-default-controller-private-cancel and https://streams.spec.whatwg.org/#rs-default-controller-private-cancel. In both places it is called via PromiseInvokeOrNoop() where the important step is

  1. Otherwise, return a promise resolved with returnValue.[[Value]].

"a promise resolved with" links to https://www.w3.org/2001/tag/doc/promises-guide/#a-promise-resolved-with which then refers to Promise.resolve() in the ecmascript spec. I found it challenging to find the part of the ecmascript spec which says that Promise.resolve() converts a thenable to a Promise, but it does.

To save you the time of chasing them down, all Source and Sink methods which are documented as "can return a promise" are called via PromiseInvokeOrNoop() or PromiseInvokeOrFallbackOrNoop() and so can return a thenable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants