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

Function sendMessageToWorker

lib/internal/worker/messaging.js:100–128  ·  view source on GitHub ↗
(source, destination, value, transferList, memory)

Source from the content-addressed store, hash-verified

98}
99
100function sendMessageToWorker(source, destination, value, transferList, memory) {
101 // We are on the main thread, we can directly process the message
102 if (destination === 0) {
103 receiveMessageFromWorker(source, value, memory);
104 return;
105 }
106
107 // Search the port to the target thread
108 const port = threadsPorts.get(destination);
109
110 if (!port) {
111 const status = new Int32Array(memory);
112 AtomicsStore(status, WORKER_MESSAGING_RESULT_INDEX, WORKER_MESSAGING_RESULT_NO_LISTENERS);
113 AtomicsStore(status, WORKER_MESSAGING_STATUS_INDEX, 1);
114 AtomicsNotify(status, WORKER_MESSAGING_STATUS_INDEX, 1);
115 return;
116 }
117
118 port.postMessage(
119 {
120 type: messageTypes.RECEIVE_MESSAGE_FROM_WORKER,
121 source,
122 destination,
123 value,
124 memory,
125 },
126 transferList,
127 );
128}
129
130function receiveMessageFromWorker(source, value, memory) {
131 let response = WORKER_MESSAGING_RESULT_NO_LISTENERS;

Callers 1

handleMessageFromThreadFunction · 0.85

Calls 3

receiveMessageFromWorkerFunction · 0.85
getMethod · 0.65
postMessageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…