wasm-idle 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@ import type Sandbox from './sandbox';
|
|
|
2
2
|
declare class Clang implements Sandbox {
|
|
3
3
|
ts: number;
|
|
4
4
|
output: any;
|
|
5
|
-
worker
|
|
5
|
+
worker?: Worker;
|
|
6
6
|
buffer: SharedArrayBuffer;
|
|
7
7
|
interruptBuffer: SharedArrayBuffer;
|
|
8
8
|
internalBuffer: string[];
|
|
@@ -10,6 +10,7 @@ declare class Clang implements Sandbox {
|
|
|
10
10
|
elapse: number;
|
|
11
11
|
uid: number;
|
|
12
12
|
log: boolean;
|
|
13
|
+
exit: boolean;
|
|
13
14
|
load(path: string, code?: string, log?: boolean): Promise<void>;
|
|
14
15
|
write(input: string): void;
|
|
15
16
|
_write(input: string): void;
|
package/dist/playground/clang.js
CHANGED
|
@@ -9,6 +9,7 @@ class Clang {
|
|
|
9
9
|
elapse = 0;
|
|
10
10
|
uid = 0;
|
|
11
11
|
log = true;
|
|
12
|
+
exit = true;
|
|
12
13
|
load(path, code = '', log = true) {
|
|
13
14
|
return new Promise(async (resolve) => {
|
|
14
15
|
this.log = log;
|
|
@@ -40,9 +41,14 @@ class Clang {
|
|
|
40
41
|
eof() {
|
|
41
42
|
}
|
|
42
43
|
run(code, prepare, log = this.log) {
|
|
44
|
+
this.exit = false;
|
|
43
45
|
return new Promise(async (resolve, reject) => {
|
|
46
|
+
if (!this.worker)
|
|
47
|
+
return reject('Worker not loaded');
|
|
44
48
|
const interrupt = new Uint8Array(this.interruptBuffer), _uid = ++this.uid;
|
|
45
49
|
const handler = (event) => {
|
|
50
|
+
if (!this.worker)
|
|
51
|
+
return reject('Worker not loaded');
|
|
46
52
|
if (_uid !== this.uid)
|
|
47
53
|
return this.worker.onmessage = null;
|
|
48
54
|
const { id, output, results, log, error, buffer } = event.data;
|
|
@@ -52,6 +58,7 @@ class Clang {
|
|
|
52
58
|
this.output(output);
|
|
53
59
|
if (results) {
|
|
54
60
|
this.elapse = Date.now() - this.begin;
|
|
61
|
+
this.exit = true;
|
|
55
62
|
resolve(results);
|
|
56
63
|
}
|
|
57
64
|
if (log)
|
|
@@ -64,7 +71,7 @@ class Clang {
|
|
|
64
71
|
interrupt[0] = 0;
|
|
65
72
|
this.worker.onmessage = handler;
|
|
66
73
|
this.begin = Date.now();
|
|
67
|
-
this.worker
|
|
74
|
+
this.worker?.postMessage({
|
|
68
75
|
code,
|
|
69
76
|
prepare,
|
|
70
77
|
buffer: this.buffer,
|
|
@@ -85,6 +92,11 @@ class Clang {
|
|
|
85
92
|
const buffer = new Int32Array(this.buffer);
|
|
86
93
|
buffer.fill(0);
|
|
87
94
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
95
|
+
if (!this.exit) {
|
|
96
|
+
this.worker?.terminate?.();
|
|
97
|
+
delete this.worker;
|
|
98
|
+
this.exit = true;
|
|
99
|
+
}
|
|
88
100
|
}
|
|
89
101
|
}
|
|
90
102
|
export default Clang;
|