웹 작업자 클라이언트에 window.alert를 넣으면 백그라운드 작업자가 작동을 멈 춥니 다. 왜 이렇게됩니까?작업자 스레드의 window.alert
즉 발신자 :
var worker = new Worker("worker.js");
// Watch for messages from the worker
worker.onmessage = function(e){
// The message from the client:
e.data
};
worker.postMessage("start");
클라이언트 (worker.js)
onmessage = function(e){
if (e.data === "start") {
// Do some computation
done()
}
};
function done(){
alert('don'); // ===> This kills the worker.
// Send back the results to the parent page
postMessage("done");
}
작업자 스레드는 console.log를 사용할 수 없습니다. – jas7
@ jas7 전용 작업자는 (이미) 콘솔을 사용할 수 있지만 공유 작업자는 사용할 수 없습니다. – maja