forked from audreyt/node-webworker-threads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
53 lines (53 loc) · 1.5 KB
/
test.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
// Generated by LiveScript 1.3.1
(function(){
var Worker, w, slice$ = [].slice;
Worker = require('./').Worker;
w = new Worker(function(){
return this.onmessage = function(arg$){
var max, i$, n, j$, to$, i;
max = arg$.data.max;
search: for (i$ = 2; i$ <= max; ++i$) {
n = i$;
for (j$ = 2, to$ = Math.sqrt(n); j$ <= to$; ++j$) {
i = j$;
if (!(n % i)) {
continue search;
}
}
postMessage({
result: n
});
}
throw 'done';
};
});
w.onmessage = function(arg$){
var result;
result = arg$.data.result;
return console.log(result + " is a prime");
};
w.onerror = function(arg$){
var message, this$ = this;
message = arg$.message;
console.log("Caught:", message);
return (typeof setImmediate != 'undefined' && setImmediate !== null
? setImmediate
: partialize$.apply(this, [setTimeout, [void 8, 100], [0]]))(function(){
return this$.terminate();
});
};
w.postMessage({
max: 100
});
function partialize$(f, args, where){
var context = this;
return function(){
var params = slice$.call(arguments), i,
len = params.length, wlen = where.length,
ta = args ? args.concat() : [], tw = where ? where.concat() : [];
for(i = 0; i < len; ++i) { ta[tw[0]] = params[i]; tw.shift(); }
return len < wlen && len ?
partialize$.apply(context, [f, ta, tw]) : f.apply(context, ta);
};
}
}).call(this);