admin管理员组文章数量:1391960
In all examples I've seen, they're similar to 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 where the ports array will ever have more than one element? Using chrome://inspect on the SharedWorker and printing out e
, I get
regardless of how many instances are spawned sharing the SharedWorker, where the length is always 1. Why isn't it just a MessageEvent instead of an array? What use case is there for it to be an array?
In all examples I've seen, they're similar to 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 where the ports array will ever have more than one element? Using chrome://inspect on the SharedWorker and printing out e
, I get
regardless of how many instances are spawned sharing the SharedWorker, where the length is always 1. Why isn't it just a MessageEvent instead of an array? What use case is there for it to be an array?
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Sep 6, 2016 at 7:43 No_nameNo_name 2,8203 gold badges34 silver badges49 bronze badges1 Answer
Reset to default 8The reason is that it reuses the MessageEvent
interface which can sometimes be dispatched with an array of multiple ports. That's all.
本文标签: javascriptWhy does the SharedWorker onConnect event have a Ports arrayStack Overflow
版权声明:本文标题:javascript - Why does the SharedWorker onConnect event have a Ports array? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744723494a2621835.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论