Re: [w3c/ServiceWorker] Avoid array manipulation in parallel (#1243)

jakearchibald commented on this pull request.



> -        1. Let |promise| be a new <a>promise</a>.
-        1. Run the following substeps <a>in parallel</a>:
-            1. Let |array| be an empty array.
-            1. [=map/For each=] |key| → |value| of <a>scope to registration map</a>:
-                1. If the [=url/origin=] of the result of <a lt="URL parser">parsing</a> |key| is the <a lt="same origin">same</a> as |client|'s [=environment settings object/origin=], and |value|'s <a>uninstalling flag</a> is unset, add the {{ServiceWorkerRegistration}} object associated with |value| to the |array|.
-            1. Resolve |promise| with |array|.
+        1. Let |client| be the [=context object=]'s [=ServiceWorkerContainer/service worker client=].
+        1. Let |promise| be [=a new promise=].
+        1. Run the following steps [=in parallel=]:
+            1. Let |registrations| be a new [=list=].
+            1. [=map/For each=] |scope| → |registration| of [=scope to registration map=]:
+                1. If the [=url/origin=] of the result of [=URL parser|parsing=] |scope| is the [=same origin|same=] as |client|'s [=environment settings object/origin=], and |registration|'s [=uninstalling flag=] is unset, then [=append=] |registration| to |registrations|.
+            1. [=Queue a task=] on |promise|'s [=relevant settings object=]'s [=responsible event loop=], using the [=DOM manipulation task source=], to run the following steps:
+                1. Let |registrationObjects| be a new [=list=].
+                1. [=list/For each=] |registration| of |registrations|, [=append=] the {{ServiceWorkerRegistration}} object associated with |registration| to |registrationObjects|.
+                1. [=Resolve=] |promise| with [=create a frozen array|a new frozen array of=] |registrationObjects|.

Ah, I thought if it wasn't otherwise stated, it'd get a default from the event loop, but yeah, one loop can have many realms.

Cheers, will fix that.

FWIW I'm not happy with the association of registration object to registration here, but that's for another PR I think.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/pull/1243#discussion_r155568168

Received on Thursday, 7 December 2017 16:18:28 UTC