我目前有2个网络工作者设置如下:
gpsThread = new Worker("js/workers/gpsd_poll.js");
gpsStarted = true;
gpsThread.onmessage = function(event) {
if (event.data !== "") {
do lots of stuff here.....
}
}
netThread = new Worker("js/workers/net_poll.js");
netStarted = true;
netThread.onmessage = function(event) {
if (event.data !== "") {
do lots of stuff here.....
}
}
当gpsThread收到消息并进行处理时,netThread必须等到gpsThread完成才开始回调。
无论如何都要让它们同时运行'?我试过像这样把它们拼凑在一起:
gpsThread = new Worker("js/workers/gpsd_poll.js");
gpsStarted = true;
netThread = new Worker("js/workers/net_poll.js");
netStarted = true;
gpsThread.onmessage = function(event) {
netThread.onmessage = function(event) {
if (event.data !== "") {
do lots of stuff here.....
}
}
if (event.data !== "") {
do lots of stuff here.....
}
}