javascript - Terminating a web worker -
i have web worker appends paragraphs div , this
var worker1 = new worker('many.js'); var worker2 = new worker('many.js'); var worker3 = new worker('many.js'); var worker4 = new worker('many.js'); worker1.onmessage = function (event) { function xx(){$(event.data).appendto('#div_1');} setinterval(xx,4000); }; worker2.onmessage = function (event) { function xx(){$(event.data).appendto('#div_2');} setinterval(xx,4400); }; function killworker(){ worker1.terminate(); }
this many.js file
function j() {return "<p>lorem ispum</p>"} postmessage(j());
i able destroy worker this
worker1.terminate();
but have liked wrap in function , try , terminate following click event button
<button onclick="javascript:killworker();">stop worker</button>
my code doesn't seem terminate worker.why doesn't work?.
is killworker
function defined in broader context? if yes, problem. try window.killworker = function() { }
instead of function killworkers() {}
explicitely define function global function accessible scope.
Comments
Post a Comment