Skip to content

Commit

Permalink
Add "abort when"/"if aborted" construct for Fetch and elsewhere
Browse files Browse the repository at this point in the history
Fixes #143.
  • Loading branch information
annevk committed Apr 21, 2018
1 parent fcacad0 commit 23ce6ea
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,78 @@ caller's algorithm. Using prose the caller has the ability to "catch" the except
another action.


<h3 id=algorithm-conditional-abort>Conditional abort</h3>

<p>Sometimes it is useful to stop performing a series of steps once a condition becomes true.

<p>To do this, state that a given series of steps will <dfn export>abort when</dfn> a specific
<var>condition</var> is reached. This indicates that the specified steps must be evaluated, not
as-written, but by additionally inserting a step before each of them that evaluates
<var>condition</var>, and if <var>condition</var> evaluates to true, skips the remaining steps.

<p>In such algorithms, the subsequent step can be annotated to run <dfn export>if aborted</dfn>, in
which case it must run if any of the preceding steps were skipped due to the <var>condition</var>
of the preceding <a>abort when</a> step evaluated to true.

<div class=example id=example-conditional-abort>
<p>The following algorithm

<ol>
<li><p>Let |result| be an empty <a>list</a>.

<li>
<p>Run these steps, but <a>abort when</a> the user clicks the "Cancel" button:

<ol>
<li><p>Compute the first million digits of <var>π</var>, and <a for=list>append</a> the result
to |result|.

<li><p>Compute the first million digits of |e|, and <a for=list>append</a> the result to
|result|.

<li><p>Compute the first million digits of <var>φ</var>, and <a for=list>append</a> the result
to |result|.
</ol>
</li>

<li><p><a>If aborted</a>, <a for=list>append</a> "<code>Didn't finish!</code>" to |result|.
</ol>

<p>is equivalent to the more verbose formulation</p>

<ol>
<li><p>Let |result| be an empty <a>list</a>.

<li>
<p>If the user has not clicked the "Cancel" button, then:

<ol>
<li><p>Compute the first million digits of <var>π</var>, and <a for=list>append</a> the result
to |result|.

<li>
<p>If the user has not clicked the "Cancel" button, then:

<ol>
<li><p>Compute the first million digits of |e|, and <a for=list>append</a> the result to
|result|.

<li><p>If the user has not clicked the "Cancel" button, then compute the first million digits
of <var>φ</var>, and <a for=list>append</a> the result to |result|.
</ol>
</ol>

<li><p>If the user clicked the "Cancel" button, then <a for=list>append</a>
"<code>Didn't finish!</code>" to |result|.
</ol>
</div>

<p class=note>Whenever this construct is used, implementations are allowed to evaluate
<var>condition</var> during the specified steps rather than before and after each step, as long as
the end result is indistinguishable. For instance, as long as |result| in the above example is not
mutated during a compute operation, the user agent could stop the computation.


<h3 id=algorithm-iteration>Iteration</h3>

<p>There's a variety of ways to repeat a set of steps until a condition is reached.
Expand Down

0 comments on commit 23ce6ea

Please sign in to comment.