mirror of
https://github.com/denoland/deno.git
synced 2025-10-01 06:31:15 +00:00
feat: support SharedArrayBuffer sharing between workers (#11040)
This commit adds support for sharing SABs between workers.
This commit is contained in:
parent
672a88f272
commit
bdfad23dd0
13 changed files with 152 additions and 0 deletions
|
@ -789,6 +789,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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue