-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathworker_wrapper.js
32 lines (27 loc) · 904 Bytes
/
worker_wrapper.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
/**
* ng-webworker - ng-webworker creates dynamic webworkers so angular apps can be multi-threaded.
* @link https://github.com/mattslocum/ng-webworker
* @license MIT
*/
(function() {
//NOTE: transferable doesn't work for the worker_wrapper.
function complete(mVal) {
// _transferable_ is added to the worker
postMessage(["complete", mVal])
}
function notify(mVal) {
// _transferable_ is added to the worker
postMessage(["notice", mVal])
}
self.onmessage = function(oEvent) {
var aFuncParts = /function\s*(\w+)(.*)/.exec(oEvent.data.fn),
aParts = oEvent.data.args,
result;
aParts.push(oEvent.data.fn);
eval("self['" + aFuncParts[1] + "'] = " + oEvent.data.fn);
postMessage([
'return',
self[aFuncParts[1]].apply(null, oEvent.data.args)
]);
};
})();