From bdfad23dd012d0c3226b466544e86109da18d09c Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 6 Jul 2021 19:42:52 +0200 Subject: feat: support SharedArrayBuffer sharing between workers (#11040) This commit adds support for sharing SABs between workers. --- cli/tests/workers/test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'cli/tests/workers/test.ts') diff --git a/cli/tests/workers/test.ts b/cli/tests/workers/test.ts index b37b7aeb1..d35dbec82 100644 --- a/cli/tests/workers/test.ts +++ b/cli/tests/workers/test.ts @@ -789,6 +789,34 @@ Deno.test({ }, }); +Deno.test({ + name: "worker SharedArrayBuffer", + fn: async function (): Promise { + const promise = deferred(); + const workerOptions: WorkerOptions = { type: "module" }; + const w = new Worker( + new URL("shared_array_buffer.ts", import.meta.url).href, + workerOptions, + ); + const sab1 = new SharedArrayBuffer(1); + const sab2 = new SharedArrayBuffer(1); + const bytes1 = new Uint8Array(sab1); + const bytes2 = new Uint8Array(sab2); + assertEquals(bytes1[0], 0); + assertEquals(bytes2[0], 0); + w.onmessage = (): void => { + w.postMessage([sab1, sab2]); + w.onmessage = (): void => { + assertEquals(bytes1[0], 1); + assertEquals(bytes2[0], 2); + promise.resolve(); + }; + }; + await promise; + w.terminate(); + }, +}); + Deno.test({ name: "Send MessagePorts from / to workers", fn: async function (): Promise { -- cgit v1.2.3