-
Notifications
You must be signed in to change notification settings - Fork 0
/
longRunningTask.js
37 lines (33 loc) · 966 Bytes
/
longRunningTask.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/** longRunningTask.js **/
const disableElm = function(elm) {
elm.classList.add('spinner');
elm.setAttribute('disabled', 'disabled');
};
const enableElm = function(elm) {
elm.classList.remove('spinner');
elm.removeAttribute('disabled');
};
const runHeavyTaskMainThread = function(elm) {
disableElm(elm);
// setTimeout exists to allow the button a chance to change
// otherwise that too is blocked by the prime calculations
setTimeout(function() {
console.log(
intensive(200000)
);
enableElm(elm);
}, 100)
};
const runHeavyTaskWorkerThread = function(elm) {
if(!window.Worker) {
alert('Web workers are not supported by your browser.')
return;
}
disableElm(elm);
const worker = new Worker("./worker.js");
worker.postMessage(200000);
worker.addEventListener('message', function(data) {
console.log(data.data);
enableElm(elm);
});
};