Skip to content

Commit

Permalink
feat(node): worker_threads
Browse files Browse the repository at this point in the history
  • Loading branch information
Mesteery committed Jan 29, 2022
1 parent 1c8e6ce commit 0ba2ab4
Show file tree
Hide file tree
Showing 4 changed files with 542 additions and 45 deletions.
2 changes: 1 addition & 1 deletion node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Deno standard library as it's a compatibility module.
- [ ] vm
- [x] wasi
- [ ] webcrypto
- [ ] worker_threads
- [x] worker_threads
- [ ] zlib

* [x] node globals _partly_
Expand Down
29 changes: 29 additions & 0 deletions node/testdata/worker_threads.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
getEnvironmentData,
isMainThread,
parentPort,
threadId,
workerData,
} from "../worker_threads.ts";
import { once } from "../events.ts";

async function message(expectedMessage: string) {
const [message] = await once(parentPort, "message");
if (message !== expectedMessage) {
// fail test
parentPort.close();
}
}

await message("Hello, how are you my thread?");
parentPort.postMessage("I'm fine!");

parentPort.postMessage({
isMainThread,
threadId,
workerData: Array.isArray(workerData) &&
workerData[workerData.length - 1] instanceof MessagePort
? workerData.slice(0, -1)
: workerData,
envData: [getEnvironmentData("test"), getEnvironmentData(1)],
});
Loading

0 comments on commit 0ba2ab4

Please sign in to comment.