admin管理员组

文章数量:1391951

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);
}

本文标签: Avoid chrome quotpages unresponsivequot upon javascript long executionStack Overflow