blob: 004bb5428132f486ff6ecc2a19114700da50f56f (
plain)
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
|
function Worker(){
var Threads;
Threads = this;
return (function(){
var prototype = constructor.prototype;
function constructor(code){
var t, this$ = this;
this.thread = t = Threads.create();
t.on('message', function(args){
return typeof this$.onmessage === 'function' ? this$.onmessage({
data: args
}) : void 8;
});
t.on('error', function(args){
return typeof this$.onerror === 'function' ? this$.onerror(args) : void 8;
});
t.on('close', function(){
return t.destroy();
});
this.terminate = function(){
return t.destroy();
};
this.addEventListener = function(event, cb){
if (event === 'message') {
return this$.onmessage = cb;
} else {
return t.on(event, cb);
}
};
this.dispatchEvent = function(event){
return t.emitSerialized(event.type, event);
};
this.postMessage = function(data){
return t.emitSerialized('message', {
data: data
});
};
if (typeof code === 'function') {
t.eval("(" + code + ")()");
} else if (code != null) {
t.load(code);
}
}
return constructor;
}());
}
|