DOMWorkerThreads: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 138: Line 138:
Downsides with this proposal:
Downsides with this proposal:
* There is no way to communicate back unless first communicated to.
* There is no way to communicate back unless first communicated to.
* The first one to instantiate a shared worker get special treatment.


=== Proposal 2 ===
=== Proposal 2 ===
Line 159: Line 160:
</blockquote>
</blockquote>


<code>connectToSharedWorker</code> creates a new <code>Worker</code> object if none exists for the given namethat interacts with the same <code>WorkerGlobalScope</code> as any previously existing <code>Worker</code>s.
<code>connectToSharedWorker</code> creates a two new <code>MessagePort</code> which are entangled with each other. One of the two ports is returned, and the other is sent to the <code>Worker</code> with the given name. If such a <code>Worker</code> does not yet exist, one is created.


When a shared <code>Worker</code> receives a message it can send data back to the sender using the <code>Event.source</code> property which is a <code>WorkerParent</code>.
The <code>Worker</code> receives the other <code>MessagePort</code> through an <code>onconnect</code> <code>Event</code> fired on the <code>WorkerGlobalScope</code> object.


Using <code>WorkerGlobalScope.postMessage</code> and <code>WorkerGlobalScope.onmessage</code> results in a message being sent to the first context that opened the shared worker (or nothing if that context is dead).
* There is no way to get a reference to the shared <code>Worker</code> object itself.
 
* Communication for shared workers is different from communication for non-shared ones.
Downsides with this proposal:
* There is no way to communicate back unless first communicated to.
* The special treatment of the first context to open a shared worker.
Confirmed users
716

edits