1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00
denoland-deno/tests/unit_node/testdata/worker_threads2.mjs

17 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");