forked from A9T9/RPA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
50 lines (42 loc) · 1.45 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
45
46
47
48
49
50
/**
* WebAssembly supported web worker bootstrapper
*/
var moduleStartTime = performance.now();
function getNamespaceMembers(module, namespace) {
const ns = {};
const dotPrefix = namespace + ".";
const dollarPrefix = namespace + "$";
const nameOffset = namespace.length + 1;
const fullNameArray = Object.keys(module).filter(x => x.startsWith(dotPrefix) || x.startsWith(dollarPrefix));
for (const fullName of fullNameArray) {
const name = fullName.substr(nameOffset);
ns[name] = module[fullName];
}
return ns;
}
function notifyModuleInitialized() {
const elapsedTime = performance.now() - moduleStartTime;
console.log(`Module is initialized in ${elapsedTime.toFixed(0)} ms`);
self.postMessage({
type: 0 /* WorkerMessageType.Init */,
data: {
moduleVersion: kantusearch.getModuleVersion()
}
});
}
/**
* Global module object which will be merged with WebAssembly module.
*/
var Module = {
onRuntimeInitialized: () => {},
postRun: [
() => {
// Emscripten generates flat names for exports with namespaces.
// We'll build an object tree from those flat names and
// merge into global object (since we're in web worker, global object is "self").
self.kantusearch = getNamespaceMembers(Module, "kantusearch");
notifyModuleInitialized();
}
]
};
importScripts("kantusearch.js", "worker-main.js");