forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
29 lines (26 loc) · 919 Bytes
/
main.ts
File metadata and controls
29 lines (26 loc) · 919 Bytes
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
// Regression test for https://github.com/denoland/deno/issues/14786
// Atomics.waitAsync in a worker requires V8 to post a foreground task
// to resolve the promise. Without the custom platform waking the event
// loop, the worker hangs forever.
Deno.test("Atomics.waitAsync resolves in worker", async () => {
const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT);
const ia = new Int32Array(sab);
const w = new Worker(new URL("./worker.ts", import.meta.url), {
type: "module",
});
await new Promise<void>((resolve, reject) => {
w.onmessage = (ev) => {
if (ev.data === "waiting") {
// Worker called waitAsync and is blocked — notify it.
Atomics.notify(ia, 0);
} else if (ev.data.ok) {
resolve();
} else {
reject(new Error(ev.data.err));
}
};
w.onerror = (e) => reject(e);
w.postMessage(ia);
});
w.terminate();
});