HTML5网络工作者和并发

时间:2015-12-08 05:03:39

标签: javascript html5 web-worker

我目前有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.....
    }
}

0 个答案:

没有答案