[heycam/webidl] Extending async iterators to support streams (#800)

I'd like to work on (this week) extending Web IDL's async iterators support to encompass [the pattern we use in Streams](https://streams.spec.whatwg.org/#rs-asynciterator). /cc @ricea

The basic idea is to add `async iterable<value_type>(...params)`. This completes the matrix of sync/async vs. value/pair, by filling out the async value quadrant.

The `params` are passed to the (already specced for key/value async iterators) asynchronous iterator initialization steps. This is necessary for the Streams design, and fairly reasonable IMO, although unprecedented in Web IDL so far.

Points for discussion:

- The streams API would like to pick the method alias name, namely `getIterator()`. For this I'd envision syntax like `async iterable<value_type> getIterator(...params)`. However, this was not implemented anywhere yet, so maybe we should instead have Web IDL generate a `values()` method. That is my current thinking.

- Since I need params here, I could add them to async iterators generally, or to all iterators. I think the cleanest way to cut this would be to add them to all async iterators, but not bother at this point for sync iterators.

- Should we generate `keys()` and `entries()` for these value async iterators? My initial leaning is to generate them (and in this way), as otherwise they're the odd iterator out. If we do, I'd much prefer to follow the array/value sync iterator precedent and have the keys be 0-based indices, instead of having them just be aliases of the values.

- Should we generate a `forEach()` function? My initial leaning is no just because of the added complexity. (E.g., do we allow each callback to return a promise? So much promise handling.) This would make it an exception among the rest of the iterator matrix, and it could be vaguely useful sometimes, but I guess we can always add it later.

- Probably we should require that all arguments in `...params` are optional, so that `for-await-of` still works. (This matches Streams.)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/800

Received on Tuesday, 24 September 2019 08:03:52 UTC