Skip to content

Conversation

nayeemrmn
Copy link
Contributor

Strengthens the type so this doesn't throw a type error:

const iterator = Deno.listen({ port: 10000 })[Symbol.asyncIterator]();
for await (const n of iterator);

i.e the iterators are also iterable.

@ry
Copy link
Member

ry commented Apr 7, 2020

I don't really understand. Why would you want to do that?

@nayeemrmn
Copy link
Contributor Author

That's how generators are defined everywhere else, this was a mistake. Generators provide this property but those type defs are hiding it. If it really needs a use case, I suppose there is a different behaviour for two loops sharing the same iterator object which might be useful to someone.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

That's how generators are defined everywhere else, this was a mistake. Generators provide this property but those type defs are hiding it. If it really needs a use case, I suppose there is a different behaviour for two loops sharing the same iterator object which might be useful to someone.

This type declaration confirms that:
https://github.com/microsoft/TypeScript/blob/712967b2780e8ecd28f8f1e2e89c1ebd2592bb4c/lib/lib.es2018.asynciterable.d.ts#L32-L45

LGTM

@bartlomieju bartlomieju merged commit 95eb6d7 into denoland:master Apr 15, 2020
@nayeemrmn nayeemrmn deleted the net-iterables branch April 15, 2020 11:07
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

Successfully merging this pull request may close these issues.

3 participants