mirror of
https://github.com/denoland/deno
synced 2024-08-25 02:57:22 +00: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");
|