Skip to content

Commit

Permalink
Restructure to expose a boolean instead of a promise
Browse files Browse the repository at this point in the history
  • Loading branch information
noamr committed Jun 11, 2023
1 parent 5705395 commit 142c1a4
Showing 1 changed file with 72 additions and 71 deletions.
143 changes: 72 additions & 71 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2711,12 +2711,15 @@ has the following <a for=struct>items</a>:
<dt><dfn export for="deferred fetch record">inactivity deferred delay</dfn> (default null)
<dd>Null or a <a>duration</a>

<dt><dfn export for="deferred fetch record">pending steps</dfn> (default null)
<dt><dfn export for="deferred fetch record">invoked callback</dfn> (default null)
<dd>Null or an algortihm accepting nothing

<dt><dfn export for="deferred fetch record">invoked</dfn> (default false)
<dt><dfn export for="deferred fetch record">sent</dfn> (default false)
<dd>A boolean

<dt><dfn export for="deferred fetch record">invoke state</dfn> (default "<code>deferred</code>")
<dd>
<p>"<code>deferred</code>", "<code>scheduled</code>", "<code>terminated</code>",
"<code>aborted</code>", or "<code>sent</code>"

<p class=note>This value can be modified <a>in parallel</a>.
</dl>


Expand All @@ -2726,79 +2729,60 @@ has the following <a for=struct>items</a>:
<dfn export for="fetch group" id=concept-fetch-group-terminate>terminated</dfn>:

<ol>
<li>
<p><a for=list>For each</a> <a for="fetch group">deferred fetch record</a>
<var>deferredRecord</var> in <var>fetchGroup</var>'s
<a for="fetch group">deferred fetch records</a> whose <a for="deferred fetch record">invoked</a> is
false:

<ol>
<li><p>If <var>deferredRecord</var>'s <a for="deferred fetch record">pending steps</a> is not
null then <a>abort</a> <var>deferredRecord</var>'s
<a for="deferred fetch record">pending steps</a>.

<li><p><a for=/>fetch</a> <var>deferredRecord</var>'s <a for="deferred fetch record">request</a>.
</ol>

<li><p>For each associated <a for="fetch group">fetch record</a> <var>record</var>,
if <var>record</var>'s <a for="fetch record">controller</a> is non-null and
<var>record</var>'s <a for="fetch record">request</a>'s <a>done flag</a> is unset or
<a for=request>keepalive</a> is false, <a for="fetch controller">terminate</a> <var>record</var>'s
<a for="fetch record">controller</a>.
</ol>

<p>When a <a for=fetch>fetch group</a> <var>fetchGroup</var> is
<dfn export for="fetch group" id=concept-fetch-group-activate>activated</dfn>:
<a for=list>for each</a> <a for=/>deferred fetch record</a> <var>deferredRecord</var> in
<var>fetchGroup</var>'s <a for="fetch group">deferred fetch records</a>:

<ol>
<li>
<p>If <var>deferredRecord</var>'s <a for="deferred fetch record">invoked</a> is true then:
<ol>
<li><p>If <var>deferredRecord</var>'s <a for="deferred fetch record">invoked callback</a> is not
null then call <var>deferredRecord</var>'s <a for="deferred fetch record">invoked callback</a>.

<li><p><a for=list>Remove</a> <var>deferredRecord</var> from <var>fetchGroup</var>'s
<a for="fetch group">deferred fetch records</a>.
</ol>

<li><p>Otherwise, if <var>deferredRecord</var>'s
<a for="deferred fetch record">pending steps</a> is not null, then <a>abort</a>
<var>deferredRecord</var>'s <a for="deferred fetch record">pending steps</a> and set
<var>deferredRecord</var>'s <a for="deferred fetch record">pending steps</a> to null.
<li><p><a for=list>For each</a> <a for="fetch group">deferred fetch record</a>
<var>deferredRecord</var> in <var>fetchGroup</var>'s
<a for="fetch group">deferred fetch records</a>: If the result of atomically exchanging the value
of <var>deferredRecord</var>'s <a for="deferred fetch record">invoke state</a> with
"<code>terminated</code>" is not "<code>sent</code>", then the user agent should
<a for=/>fetch</a> <var>deferredRecord</var>'s <a for="deferred fetch record">request</a>. The
exact time in which the <a for=/>fetch</a> takes place is <a>implementation-defined</a>.
</ol>

<p>When a <a for=fetch>fetch group</a> <var>fetchGroup</var> is
<dfn export for="fetch group" id=concept-fetch-group-deactivate>deactivated</dfn>:
<a for=list>For each</a> <a>deferred fetch record</a> <var>deferredRecord</var> in
<var>fetchGroup</var>'s <a for="fetch group">deferred fetch records</a> whose
<a for="deferred fetch record">inactivity deferred delay</a> is not null:

<ol>
<li><p>Set <var>deferredRecord</var>'s <a for="deferred fetch record">invoke state</a> to
"<code>scheduled</code>".

<li>
<p><a for=list>For each</a> <a>deferred fetch record</a> <var>deferredRecord</var> in
<var>fetchGroup</var>'s <a for="fetch group">deferred fetch records</a> whose
<a for="deferred fetch record">inactivity deferred delay</a> is not null: set
<var>deferredRecord</var>'s <a for="deferred fetch record">pending steps</a> to running the
following steps <a>in parallel</a>:
<p>Run the following steps <a>in parallel</a>:

<ol>
<li><p>Wait until <var>deferredRecord</var>'s
<a for="deferred fetch record">inactivity deferred delay</a> have passed.

<li>
<p><a>Queue a fetch task</a> to run the following steps with
<a for="fetch record">request</a>'s <a for=request>client</a>'s
<a for="environment settings object">global object</a>:

<ol>
<li><p><a for=/>Fetch</a> <var>record</var>'s <a for="fetch record">request</a>.

<li><p>Set <var>deferredRecord</var> <a for="deferred fetch record">invoked</a> to true.
</ol>
</li>
<li><p>The user agent should wait until <var>deferredRecord</var>'s
<a for="deferred fetch record">inactivity deferred delay</a> have passed or until
<var>deferredRecord</var>'s <a for="deferred fetch record">invoke state</a> is not
"<code>scheduled</code>". The user agent may wait for a longer or shorter period time, e.g., to
optimize batching of deferred fetches.

<li><p>If the result of atomically exchanging the value of <var>deferredRecord</var>'s
<a for="deferred fetch record">invoke state</a> with "<code>sent</code>" is
"<code>scheduled</code>", then <a for=/>fetch</a> <var>record</var>'s
<a for="fetch record">request</a>.
</ol>
</li>
</ol>

<p>When a <a for=fetch>fetch group</a> <var>fetchGroup</var> is
<dfn export for="fetch group" id=concept-fetch-group-reactivate>reactivated</dfn>:
<a for=list>For each</a> <a for=/>deferred fetch record</a> <var>deferredRecord</var> in
<var>fetchGroup</var>'s <a for="fetch group">deferred fetch records</a>: If the result of atomically
exchanging the value of <var>deferredRecord</var>'s <a for="deferred fetch record">invoke state</a>
with "<code>deferred</code>" is "<code>sent</code>", then <a for=list>remove</a>
<var>deferredRecord</var> from <var>fetchGroup</var>'s
<a for="fetch group">deferred fetch records</a> and set <var>deferredRecord</var>'s
<a for="deferred fetch record">sent</a> to true.


<h3 id=resolving-domains>Resolving domains</h3>

<div algorithm>
Expand Down Expand Up @@ -8637,19 +8621,29 @@ dictionary DeferredRequestInit : RequestInit {
DOMHighResTimeStamp backgroundTimeout;
};

interface FetchLaterResult {
readonly attribute boolean sent;
};

partial interface mixin WindowOrWorkerGlobalScope {
[NewObject] Promise&lt;Response> fetchLater(RequestInfo input, optional DeferredRequestInit init = {});
[NewObject] FetchLaterResult fetchLater(RequestInfo input, optional DeferredRequestInit init = {});
};
</pre>

<p>A {{FetchLaterResult}} has an associated <a>deferred fetch record</a>
<dfn for=FetchLaterResult>deferred record</dfn>.

<div algorithm>
<p>The <dfn attribute for=FetchLaterResult><code>sent</code></dfn> getter steps are to return
<a>this</a>'s <a for=FetchLaterResult>deferred record</a>'s <a for="deferred fetch record">sent</a>.
</div>

<div algorithm="dom-fetch-later">
<p>The
<dfn id=dom-global-fetch-later method for=WindowOrWorkerGlobalScope><code>fetchLater(<var>input</var>, <var>init</var>)</code></dfn>
method steps are:

<ol>
<li><p>Let <var>promise</var> be a new promise.

<li><p>Let <var>requestObject</var> be the result of invoking the initial value of {{Request}} as
constructor with <var>input</var> and <var>init</var> as arguments. If that threw an exception,
<a for=/>reject</a> <var>promise</var> with that exception and return <var>promise</var>.
Expand All @@ -8669,17 +8663,24 @@ method steps are:
<li><p>If <var>backgroundTimeout</var> is not a {{DOMHighResTimeStamp}} then throw a {{TypeError}}.

<li><p>Let <var>deferredRecord</var> be the result of calling
<a>request a deferred fetch</a> given <var>request</var> and <var>backgroundTimeout</var>. If that
threw an exception, <a for=/>reject</a> <var>promise</var> with that exception and return
<var>promise</var>.
<a>request a deferred fetch</a> given <var>request</var> and <var>backgroundTimeout</var>. This
may throw an exception.

<li><p>Set <var>deferredRecord</var>'s <a for="deferred fetch record">invoke callback</a> to
<a for=/>resolve</a> <var>promise</var>.
<li>
<p><a for=AbortSignal lt=add>Add the following abort steps</a> to <var>requestObject</var>'s
<a for=Request>signal</a>:

<li><p><a for=AbortSignal lt=add>Add the following abort steps</a> to <var>requestObject</var>'s
<a for=Request>signal</a>: <a for=list>remove</a> <var>deferredRecord</var> from
<var>request</var>'s <a for=request>client</a>'s <a for=fetch>fetch group</a>'s
<a for="fetch group">deferred fetch records</a>.
<ol>
<li><p>Set <var>deferredRecord</var>'s <a for="deferred fetch record">invoke state</a> to
"<code>aborted</code>".

<li><p><a for=list>Remove</a> <var>deferredRecord</var> from
<var>request</var>'s <a for=request>client</a>'s <a for=fetch>fetch group</a>'s
<a for="fetch group">deferred fetch records</a>.
</ol>

<li><p>Return a new {{FetchLaterResult}} whose <a for=FetchLaterResult>deferred record</a> is
<var>deferredRecord</var>.
</ol>


Expand Down

0 comments on commit 142c1a4

Please sign in to comment.