-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenscad-runner.js
35 lines (31 loc) · 960 Bytes
/
openscad-runner.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
// Output is {outputs: [name, content][], mergedOutputs: [{(stderr|stdout|error)?: string}], exitCode: number}
export function spawnOpenSCAD({inputs, args, outputPaths, zipArchives}) {
var worker;
var rejection;
function terminate() {
if (!worker) {
return;
}
worker.terminate();
worker = null;
}
const promise = new Promise((resolve, reject) => {
worker = new Worker('./openscad-worker-inlined.js');
//if (navigator.userAgent.indexOf(' Chrome/') < 0) {
// worker = new Worker('./openscad-worker-firefox.js'); // {'type': 'module'}
//} else {
// worker = new Worker('./openscad-worker.js', {'type': 'module'});
//}
rejection = reject;
worker.onmessage = e => {
resolve(e.data);
terminate();
}
worker.postMessage({inputs, args, outputPaths, zipArchives})
});
promise.kill = () => {
rejection({error: 'Terminated'});
terminate();
}
return promise;
}