Skip to content

Async iterators #580

Closed
Closed
@jakearchibald

Description

@jakearchibald

It'd be nice if we could create async iterators in a similar way to iterators.

interface Whatever {
  //
  async_iterable<Something>;
};

The prose would need to be a little more complicated than iterable, probably written like a generator.

For example:

interface SlowCounter {
  //
  async_iterable<unsigned long long>;
};

To asynchronously iterate over a SlowCounter, run the following steps:

  1. Run these steps in parallel:
    1. Let i be 0.
    2. While true:
      1. Wait 1 second.
      2. Yield the value of i using the networking task source.
      3. Increment i by 1.

"Yield" would queue a task on the given task source to resolve the iteration's promise with the given value. The algorithm would not advance until the next iteration was requested.

I guess it's tricky as task sources are an HTML thing, but I can't see how it can be handled correctly otherwise.

Metadata

Metadata

Assignees

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