|
|
| Line 159: |
Line 159: |
| </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).
| |
| | |
| 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.
| |