Avoid chrome "pages unresponsive" upon javascript long execution - Stack Overflow

I have a javascript LONG execution procedure (and reasons to have it). How can I avoid in javascript th

I have a javascript LONG execution procedure (and reasons to have it). How can I avoid in javascript the message on the client machines? I read something about --disable-hang-monitor, but is a mand line argument or setting, not javascript (also, I read isnt working allways)

I have a javascript LONG execution procedure (and reasons to have it). How can I avoid in javascript the message on the client machines? I read something about --disable-hang-monitor, but is a mand line argument or setting, not javascript (also, I read isnt working allways)

Share Improve this question asked Mar 8, 2019 at 21:52 gtryonpgtryonp 4075 silver badges13 bronze badges 4
  • Do async and defer attributes on script tags solve the problem? – Ali Sheikhpour Commented Mar 8, 2019 at 21:58
  • In most cases there should be no valid reasons to have such scripts. You say that you have "reasons", what are they? What is the code doing? – battlmonstr Commented Mar 8, 2019 at 22:07
  • Thanks Ali Sheikhpour for your ment. but neither async nor defer avoid the message when the scripts takes a long time. – gtryonp Commented Mar 10, 2019 at 6:23
  • Thanks battlmonstr for your ment. (In short: A project to create software capable to write code business logic by itself), But please focus in help us -if you know how- with the question. – gtryonp Commented Mar 10, 2019 at 6:44
Add a ment  | 

1 Answer 1

Reset to default 5

Assuming you are doing plex calculations that can't be broken down in smaller chunks, web workers seem to the solution to me. It's the javascript mechanism to run code in a separate thread, but you have to municate with that thread (called a worker) via messaging: https://developer.mozilla/en-US/docs/Web/API/Web_Workers_API/Using_web_workers

var myWorker = new Worker('worker.js');
first.onchange = function() {
  myWorker.postMessage([first.value,second.value]);
  console.log('Message posted to worker');
}

second.onchange = function() {
  myWorker.postMessage([first.value,second.value]);
  console.log('Message posted to worker');
}

myWorker.onmessage = function(e) {
  result.textContent = e.data;
  console.log('Message received from worker');
}

In the worker:

onmessage = function(e) {
  console.log('Message received from main script');
  var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
  console.log('Posting message back to main script');
  postMessage(workerResult);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744756760a4591928.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信