diff options
author | Luca Casonato <hello@lcas.dev> | 2021-07-06 19:42:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 19:42:52 +0200 |
commit | bdfad23dd012d0c3226b466544e86109da18d09c (patch) | |
tree | f59bfc463f29047df80c48abbe299e55a16b8622 /cli/tests | |
parent | 672a88f2727286233ab904e23a9145aa5563a834 (diff) |
feat: support SharedArrayBuffer sharing between workers (#11040)
This commit adds support for sharing SABs between workers.
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/workers/shared_array_buffer.ts | 9 | ||||
-rw-r--r-- | cli/tests/workers/test.ts | 28 |
2 files changed, 37 insertions, 0 deletions
diff --git a/cli/tests/workers/shared_array_buffer.ts b/cli/tests/workers/shared_array_buffer.ts new file mode 100644 index 000000000..4af95863a --- /dev/null +++ b/cli/tests/workers/shared_array_buffer.ts @@ -0,0 +1,9 @@ +self.postMessage("ready"); + +globalThis.addEventListener("message", (e) => { + const bytes1 = new Uint8Array(e.data[0]); + const bytes2 = new Uint8Array(e.data[1]); + bytes1[0] = 1; + bytes2[0] = 2; + self.postMessage("done"); +}); 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 @@ -790,6 +790,34 @@ Deno.test({ }); Deno.test({ + name: "worker SharedArrayBuffer", + fn: async function (): Promise<void> { + 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<void> { const result = deferred(); |