0
Google지도에서 마커를 클릭하여 웹 근로자를 시작합니다. 클릭 이벤트가 발생하면 해당 마커 (내 경우에는 sensorid)의 ID가 작업자를 시작하는 함수로 전달되고 작업자는 해당 ID에 대해 데이터를 가져옵니다. 모든 것이 잘 작동합니다. 그러나 나는 다시 이벤트가 발생하거나 새로운 sensorid로 함수가 호출 될 때 작업자를 다시 시작하려고합니다. 작업자를 시작하는 기능 코드. 콘솔에서동일한 이벤트가 발생하면 웹 근로자를 종료하고 다시 시작하십시오.
function showgraph(sensorid) {
console.log("showing graph of " + sensorid);
var graphworker = undefined;
if (typeof (graphworker) == "undefined") {
graphworker = new Worker('worker/graphworker.js');
graphworker.onmessage = function (event) {
// other task will happen there
}
graphworker.postMessage(sensorid);
}
else {
graphworker.terminate();
graphworer = undefined;
console.log("worker is stoped");
//but my previuos worker is not terminating here
}
}
출력
이내 작업자 코드는 내가 코드에 따라이 문제를 해결했다
self.addEventListener('message', function (sensorid)
{
var t = setInterval(fun, 3000);
function fun() {
var id = sensorid.data;
console.log("form graph worker"+ id);
},false);