我正在浏览webworkers文档,我找不到任何支持两个webworkers之间通信的api。这是我的上下文,现在我需要直接与worker2通信worker1?不是来自UI。就像线程消息一样。
app.js
var worker1 = new Worker("worker1.js");
var worker2 = new Worker("worker2.js");
worker1.onmessage=function(e) {
console.log("msg from worker1"+e.data);
}
worker1.postMessage("ping worker1");
worker2.onmessage=function(e) {
console.log("msg from worker2"+e.data);
}
worker2.postMessage("ping worker2");
worker1.js
onmessage=function(e) {
postMessage(e.data)
}
worker2.js
onmessage=function(e) {
postMessage(e.data)
}
如果有可能,请粘贴一些示例。