Skip to content

Commit

Permalink
Tweak async iterator algorithms
Browse files Browse the repository at this point in the history
Make both the "async iterator initialization steps" and the "get the next iteration result" take two arguments: the instance, and the async iterator. This ends up being more ergonomic than using the "current state" concept.
  • Loading branch information
domenic committed Sep 24, 2019
1 parent 9c59759 commit c14701b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions index.bs
Expand Up @@ -4299,19 +4299,17 @@ and {{@@asyncIterator}} properties on its [=interface prototype object=].

Prose accompanying an [=interface=] with an [=asynchronously iterable declaration=] must define a
<dfn id="dfn-get-the-next-iteration-result">get the next iteration result</dfn> algorithm.
This algorithm receives a <b>[=this=]</b> value, which is an instance of the [=interface=] that it
is defined for, and the <dfn export>current state</dfn>.
This algorithm receives the instance of the [=interface=] that is being iterated, as well as the
async iterator itself (which can be useful for storing state).
It must return a {{Promise}} that either resolves with undefined – to signal the end of the
iteration – or a tuple with three elements:
iteration – or a tuple with two elements:

1. a value of the first type given in the declaration;
1. a value of the second type given in the declaration;
1. an opaque value that is passed back to the next invocation of the algorithm as the
<b>[=current state=]</b>.
1. a value of the second type given in the declaration.

The prose may also define <dfn>asynchronous iterator initialization steps</dfn> for the
[=interface=] with an [=asynchronously iterable declaration=], which would then be called with the
newly created iterator object.
instance of the [=interface=] being iterated, as well as the newly created iterator object.

[=Interfaces=] with an [=asynchronously iterable declaration=] must not have any
[=interface members=] named "<code>entries</code>", "<code>keys</code>", or "<code>values</code>",
Expand Down Expand Up @@ -4341,26 +4339,32 @@ or have any [=inherited interfaces=] that have [=interface members=] with these

<blockquote>

To [=get the next iteration result=] for <code class="idl">SessionManager</code>, run the
following steps:
The [=async iterator initialization steps=] for a <code class="idl">SessionManager</code>
async iterator |iterator| are:

1. Set |iterator|'s current state to "not yet started".

To [=get the next iteration result=] for a <code class="idl">SessionManager</code>
|manager| and its async iterator |iterator|:

1. Let |promise| be a new promise.
1. Let |key| be the following value, if it exists, or null otherwise:
<dl class="switch">
: If <b>current state</b> is "not yet started"
:: the smallest username in <b>this</b>'s open sessions, in lexicographical order
: If |iterator|'s current state is "not yet started"
:: the smallest username in |manager|'s open sessions, in lexicographical order

: Otherwise
:: the smallest username in <b>this</b>'s open sessions that is greater than
<b>current state</b>, in lexicographical order
:: the smallest username in |manager|'s open sessions that is greater than
|iterator|'s current state, in lexicographical order
</dl>

Note: <b>current state</b> might no longer be present in the open sessions.
Note: |iterator|'s current state might no longer be present in the open sessions.
1. If |key| is null, then:
1. Resolve |promise| with undefined.
1. Otherwise:
1. Let |session| be the <code class="idl">Session</code> object corresponding to |key|.
1. Resolve |promise| with (|username|, |session|, |username|).
1. Resolve |promise| with (|username|, |session|).
1. Set |iterator|'s current state to |username|.
1. Return |promise|.

</blockquote>
Expand Down

0 comments on commit c14701b

Please sign in to comment.