diff --git a/fetch.bs b/fetch.bs index dd3a2f0b0..842262772 100644 --- a/fetch.bs +++ b/fetch.bs @@ -2711,12 +2711,15 @@ has the following items:
inactivity deferred delay (default null)
Null or a duration -
pending steps (default null) -
invoked callback (default null) -
Null or an algortihm accepting nothing - -
invoked (default false) +
sent (default false)
A boolean + +
invoke state (default "deferred") +
+

"deferred", "scheduled", "terminated", + "aborted", or "sent" + +

This value can be modified in parallel. @@ -2726,79 +2729,60 @@ has the following items: terminated:

    -
  1. -

    For each deferred fetch record - deferredRecord in fetchGroup's - deferred fetch records whose invoked is - false: - -

      -
    1. If deferredRecord's pending steps is not - null then abort deferredRecord's - pending steps. - -

    2. fetch deferredRecord's request. -

    -
  2. For each associated fetch record record, if record's controller is non-null and record's request's done flag is unset or keepalive is false, terminate record's controller. -

- -

When a fetch group fetchGroup is -activated: -for each deferred fetch record deferredRecord in -fetchGroup's deferred fetch records: - -

    -
  1. -

    If deferredRecord's invoked is true then: -

      -
    1. If deferredRecord's invoked callback is not - null then call deferredRecord's invoked callback. - -

    2. Remove deferredRecord from fetchGroup's - deferred fetch records. -

    -
  2. Otherwise, if deferredRecord's - pending steps is not null, then abort - deferredRecord's pending steps and set - deferredRecord's pending steps to null. +

  3. For each deferred fetch record + deferredRecord in fetchGroup's + deferred fetch records: If the result of atomically exchanging the value + of deferredRecord's invoke state with + "terminated" is not "sent", then the user agent should + fetch deferredRecord's request. The + exact time in which the fetch takes place is implementation-defined.

When a fetch group fetchGroup is deactivated: +For each deferred fetch record deferredRecord in +fetchGroup's deferred fetch records whose +inactivity deferred delay is not null:

    +
  1. Set deferredRecord's invoke state to + "scheduled". +

  2. -

    For each deferred fetch record deferredRecord in - fetchGroup's deferred fetch records whose - inactivity deferred delay is not null: set - deferredRecord's pending steps to running the - following steps in parallel: +

    Run the following steps in parallel:

      -
    1. Wait until deferredRecord's - inactivity deferred delay have passed. - -

    2. -

      Queue a fetch task to run the following steps with - request's client's - global object: - -

        -
      1. Fetch record's request. - -

      2. Set deferredRecord invoked to true. -

      -
    3. +
    4. The user agent should wait until deferredRecord's + inactivity deferred delay have passed or until + deferredRecord's invoke state is not + "scheduled". The user agent may wait for a longer or shorter period time, e.g., to + optimize batching of deferred fetches. + +

    5. If the result of atomically exchanging the value of deferredRecord's + invoke state with "sent" is + "scheduled", then fetch record's + request.

+

When a fetch group fetchGroup is +reactivated: +For each deferred fetch record deferredRecord in +fetchGroup's deferred fetch records: If the result of atomically +exchanging the value of deferredRecord's invoke state +with "deferred" is "sent", then remove +deferredRecord from fetchGroup's +deferred fetch records and set deferredRecord's +sent to true. + +

Resolving domains

@@ -8637,19 +8621,29 @@ dictionary DeferredRequestInit : RequestInit { DOMHighResTimeStamp backgroundTimeout; }; +interface FetchLaterResult { + readonly attribute boolean sent; +}; + partial interface mixin WindowOrWorkerGlobalScope { - [NewObject] Promise<Response> fetchLater(RequestInfo input, optional DeferredRequestInit init = {}); + [NewObject] FetchLaterResult fetchLater(RequestInfo input, optional DeferredRequestInit init = {}); }; +

A {{FetchLaterResult}} has an associated deferred fetch record +deferred record. + +

+

The sent getter steps are to return +this's deferred record's sent. +

+

The fetchLater(input, init) method steps are:

    -
  1. Let promise be a new promise. -

  2. Let requestObject be the result of invoking the initial value of {{Request}} as constructor with input and init as arguments. If that threw an exception, reject promise with that exception and return promise. @@ -8669,17 +8663,24 @@ method steps are:

  3. If backgroundTimeout is not a {{DOMHighResTimeStamp}} then throw a {{TypeError}}.

  4. Let deferredRecord be the result of calling - request a deferred fetch given request and backgroundTimeout. If that - threw an exception, reject promise with that exception and return - promise. + request a deferred fetch given request and backgroundTimeout. This + may throw an exception. -

  5. Set deferredRecord's invoke callback to - resolve promise. +

  6. +

    Add the following abort steps to requestObject's + signal: -

  7. Add the following abort steps to requestObject's - signal: remove deferredRecord from - request's client's fetch group's - deferred fetch records. +

      +
    1. Set deferredRecord's invoke state to + "aborted". + +

    2. Remove deferredRecord from + request's client's fetch group's + deferred fetch records. +

    + +
  8. Return a new {{FetchLaterResult}} whose deferred record is + deferredRecord.