Skip to content

Iterator helpers throw the error too lateΒ #41648

Closed
@benjamingr

Description

@benjamingr

Currently iterator helpers throw type errors on first iteration - they should likely do so synchronously.

For example:

Readable.from([1]).map(1); // returns a stream, for...awaiting it will throw the error

Instead I think we should throw synchronously, which is what I believe the spec says.

A fix would be to take the code in operators.js that does validations that is in an async generator and wrap it so that it does those validations in a function called before the async generator.

So instead of:

async function* map(...) {
  validateFoo(...);
}

We'd do:

function map(...) { // not async to throw synchronously
  validateFoo(...);
  return async function*() {

  }();
}

The test at test-stream-map would similarly need to be updated from rejecting asynchronously on iteration to throwing synchronously. I've opened an issue in the iterator helper proposal to be sure.

That's my understanding here: https://tc39.es/proposal-iterator-helpers/#sec-asynciteratorprototype.map

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions