Why is there an array of ports in the SharedWorker onConnect event?

In all the examples I've seen, they look like this

onconnect = function(e) { var port = e.ports[0]; port.onmessage = function(e) { var workerResult = 'Result: ' + (e.data[0] * e.data[1]); port.postMessage(workerResult); } port.start(); } 

Is there an instance in which an array of ports will have more than one element? Using chrome: // check on SharedWorker and print e , I get

MessageEvent

no matter how many instances are generated in conjunction with SharedWorker, where the length is always 1. Why is it not just a MessageEvent, not an array? What use case is needed for this array?

+5
source share
1 answer

The reason is that it reuses the MessageEvent interface, which can sometimes be sent with an array of multiple ports. It's all.

+2
source

All Articles