-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (23 loc) · 736 Bytes
/
script.js
File metadata and controls
34 lines (23 loc) · 736 Bytes
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
(function(){
var buttonWithoutWebworker = document.getElementById('without-webworker'),
buttonWithWebworker = document.getElementById('with-webworker'),
worker = new Worker('webworker.js');
buttonWithoutWebworker.addEventListener('click', calculateWithoutWebworker);
buttonWithWebworker.addEventListener('click', calculateWithWebworker);
worker.addEventListener('message', function(event) {
done(event.data);
});
function calculateWithoutWebworker () {
var j = 0;
for (var i = 0; i < 1000000000; i++) {
j = j + i;
};
done(j);
};
function calculateWithWebworker () {
worker.postMessage('calculate');
};
function done (amount) {
alert('calculation done, result: ' + amount);
};
})();