-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
44 lines (41 loc) · 1.06 KB
/
worker.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
38
39
40
41
42
43
44
// Do the actual work of getting a message
console.log('worker.js launched');
function getMessage() {
var x = new XMLHttpRequest();
x.open('GET', 'serviceworker/sleep/?action=timeout&user=ben&id=testing1234567890', false);
//x.responseType = "arraybuffer";
var result = [];
x.onload = function(e) {
if (e.target.response) {
result.push[e.target.response];
} else {
console.log('response is null');
}
}
console.log('worker.js send+');
x.send(null);
console.log("worker.js: send- result: " + result);
return result;
}
// Do busy-waiting, do not proceed until we get a message
function subReceiveMessage() {
do {
var message = getMessage();
if (message.length > 0) {
console.log("worker.js receive msg:" + message);
return message;
}
} while (1);
}
(function workerStart() {
console.log('workerStart+');
for (;;) {
do {
var message = subReceiveMessage();
if (message) {
console.log("worker.js receive msg:" + message);
break;
}
} while(100);
}
})();