mirror of
https://github.com/denoland/deno.git
synced 2024-12-30 02:59:11 -05:00
18 lines
563 B
JavaScript
18 lines
563 B
JavaScript
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||
|
import { parentPort, workerData } from "node:worker_threads";
|
||
|
import { once } from "node:events";
|
||
|
|
||
|
async function message(expectedMessage) {
|
||
|
const [message] = await once(parentPort, "message");
|
||
|
if (message !== expectedMessage) {
|
||
|
console.log(`Expected the message "${expectedMessage}", but got`, message);
|
||
|
// fail test
|
||
|
parentPort.close();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const uint = new Uint8Array(workerData.sharedArrayBuffer);
|
||
|
uint[0]++;
|
||
|
await message("Hello");
|
||
|
parentPort.postMessage("Hello");
|