-
Notifications
You must be signed in to change notification settings - Fork 5
/
pseudoworker.js
63 lines (46 loc) · 1.35 KB
/
pseudoworker.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use strict";
function PseudoWorker(url) {
var me = this;
var buffered_messages = [];
function Child() {
}
Child.prototype.postMessage = function (msg) {
me.onmessage({data: msg});
};
Child.prototype.onmessage = function (msg) {
};
var child = new Child();
this.child = child;
if (typeof JslinuxWorker != "undefined") {
JslinuxWorker(child, true);
return;
}
var success = function () {
new JslinuxWorker(child, true);
var pushmsgtome = function (msg) {
child.onmessage({data: msg});
};
// replace postMessage hook
me.postMessage = pushmsgtome.bind(me);
var i;
for (i = 0; i < buffered_messages.length; i++) {
me.postMessage(buffered_messages[i]);
}
// TODO:
//delete this['buffered_messages'];
};
var error = function () {
throw 'Error loading pseudoworker body..';
};
// buffer for messages until fully loaded...
this.buffered_messages = buffered_messages;
loadScript(url, success, error);
}
//this function will be discarded when everything is loaded...
PseudoWorker.prototype.postMessage = function (msg) {
this.buffered_messages.push(msg);
};
PseudoWorker.prototype.onmessage = function (evt) {
};
PseudoWorker.prototype.close = function () {
};