MCPcopy Index your code
hub / github.com/nodejs/node / roundTripViaWorker

Function roundTripViaWorker

test/parallel/test-crypto-keyobject-clone-transfer.js:55–79  ·  view source on GitHub ↗
(key)

Source from the content-addressed store, hash-verified

53}
54
55async function roundTripViaWorker(key) {
56 const worker = new Worker(`
57 'use strict';
58 const { parentPort } = require('node:worker_threads');
59 const { types: { isKeyObject } } = require('node:util');
60
61 parentPort.once('message', ({ key, expectedType }) => {
62 try {
63 if (!isKeyObject(key) || key.type !== expectedType) {
64 throw new Error('KeyObject slot mismatch in worker');
65 }
66 parentPort.postMessage({ key });
67 } catch (err) {
68 parentPort.postMessage({ error: err.stack || err.message });
69 }
70 });
71 `, { eval: true });
72
73 worker.postMessage({ key, expectedType: key.type });
74 const [msg] = await once(worker, 'message');
75 await worker.terminate();
76
77 assert.strictEqual(msg.error, undefined, msg.error);
78 return msg.key;
79}
80
81function hmacDigest(key) {
82 return createHmac('sha256', key).update('payload').digest('hex');

Calls 3

postMessageMethod · 0.95
terminateMethod · 0.95
onceFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…