Skip to content

ReadableStream.values().return(Promise) inconsistent with async generator behavior #1522

@HansBrende

Description

@HansBrende

What is the issue with the Web IDL Standard?

For background, see the discussion here: https://gist.github.com/MattiasBuelens/496fc1d37adb50a733edd43853f2f60e

In short, I noticed while trying to drop a spec-compliant polyfill for ReadableStream's async iteration into Typescript that the types weren't matching up with AsyncIterator. The return method for async generators can accept a promise, rather than a plain value, which is awaited and unwrapped into the return value like so: {done: true, value: resultOfAwaitedPromise}. Whereas, the async iterator corresponding to the webidl spec seems to not do this, instead returning {done: true, value: unawaitedPromise}.

To illustrate the discrepancy:

let gen = (async function*() {})();
await gen.return(Promise.resolve('foo'));
// -> { done: true, value: 'foo' }

let gen = new ReadableStream().values();
await gen.return(Promise.resolve('foo'));
// -> { done: true, value: Promise {<fulfilled>: 'foo'} }

So I am curious if this is an oversight somewhere or intentional for some reason?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions