Re: [heycam/webidl] Async iterators (#580)

Restating:
* @jakearchibald is proposing an analog for `iterable<T>` where the interface itself is an iterable
* @mkruisselbrink is interested in an analog for methods that return `sequence<T>` which is iterable

In the OP, `async_iterable<T>` is like `iterable<T>` but only (so far) defines the `[@@asyncIterable]()` method, so you get:

```js
let sum = 0;
for await (const i of slowCounter) { sum += i; }
```

Whereas @mkruisselbrink is after:
```js
let sum = 0;
for await (const i of someObject.getSlowCounter()) { sum += i; }
```

(Aside: for sync `iterable<T>` we provide `[@@iterator]()` as the bare minimum, as well as `entries()`, `values()`, `keys()` and `forEach()`, following the common methods on Array/Map/Set. So far as I know, we haven't evolved such a pattern for async iterables in the platform.)

With the OP proposal, you'd need to write:
```webidl
interface Whatever {
  WhateverSomethingAsyncIterator getSomethings();
}
interface WhateverSomethingAsyncIterator {
  async_iterable<Something>;
}
```

Which, if you're thinking of this as an async replacement for `sequence<T> getSomethings()` is fairly verbose.

Both use cases seem legitimate. I guess I would assume `async_iterable<T>` would behave per the OP, and we'd want something like `async_sequence<T>` for the second use case?

-- 
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/580#issuecomment-415126284

Received on Wednesday, 22 August 2018 18:09:04 UTC