如果我将 window.alert 放在 webworker 客户端上,那么后台工作人员将停止工作。为什么会这样?
即调用者:
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");
}