-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.js
58 lines (46 loc) · 1.23 KB
/
main.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
54
55
56
57
58
// @ts-check
/* eslint-disable no-undef */
import * as objectbufferModules from "../src";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import Worker from "worker-loader!./Worker.js";
const ob = objectbufferModules.createObjectBuffer(
2048,
{
some: {
nested: [
{
thing: "im the value to follow",
},
],
},
},
{},
"shared"
);
// o.yetAnother = [234, 234, "asf"];
// console.log(JSON.stringify(o, null, 2));
const ab = objectbufferModules.getUnderlyingArrayBuffer(ob);
const worker = new Worker();
worker.postMessage(ab);
// expose to the console
globalThis.theObjectBuffer = ob;
const input = document.createElement("input");
const button = document.createElement("button");
input.type = "text";
button.textContent = "Send to the worker's console";
document.body.appendChild(input);
document.body.appendChild(button);
button.addEventListener("click", () => {
if (
ab instanceof SharedArrayBuffer &&
objectbufferModules.acquireLock(1, ob)
) {
ob.some.nested[0].thing = input.value;
if (!objectbufferModules.releaseLock(1, ob)) {
console.warn("releaseLock failed ??");
}
} else {
console.warn("where is my lock ??");
}
});