Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from(): Support async iterable conversion #193

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

domfarolino
Copy link
Collaborator

@domfarolino domfarolino commented Jan 27, 2025

This PR closes #191 by spec'ing async iterable support. Along with support for general iteration over async iterables, we support consulting the Subscriber's signal to discontinue the iteration at three points:

  1. Immediately on subscription, so that we don't even pull out the iterator from the iterable. This matches the Chromium implementation and tests.
  2. After we obtain the iterator, the act of which may abort the signal. This also matches the Chromium implementation and tests: normal case, error case.
  3. Before we start each new iteration, to ensure we don't start after the signal has already been aborted. This matches the Chromium implementation and tests.

Additionally, an abort algorithm to call ECMAScript's AsyncIteratorClose() abstract operation is added to the subscriber's signal before iteration begins. This ensures that the iterator's return() method is called with the abort signal's abort reason if it gets aborted before the iteration organically completes. This is also tested (see https://wpt.fyi/results/dom/observable/tentative/observable-from.any.html) in a number of situations.

As alluded to, we mostly delegate to various ECMAScript abstract operations that govern iteration, but once whatwg/webidl#1397 lands should be able to use the abstractions offered in Web IDL directly, instead of manage most of it manually here. For now, this PR is somewhat redundant with the Web IDL one. It uses similar constructs to iterate over the async iterator.


Preview | Diff

@domfarolino domfarolino changed the title Spec async iterable support `from(): Support async iterable conversion Jan 27, 2025
@domfarolino domfarolino changed the title `from(): Support async iterable conversion from(): Support async iterable conversion Jan 27, 2025
@domfarolino domfarolino merged commit 6e0bbcd into master Jan 27, 2025
2 checks passed
@domfarolino domfarolino deleted the from-async-iterable-support branch January 27, 2025 23:38
github-actions bot added a commit that referenced this pull request Jan 27, 2025
SHA: 6e0bbcd
Reason: push, by domfarolino

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

Spec async iterable from() conversion
1 participant