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

Function createMainThreadPort

lib/internal/worker/messaging.js:148–168  ·  view source on GitHub ↗
(threadId)

Source from the content-addressed store, hash-verified

146}
147
148function createMainThreadPort(threadId) {
149 // Create a channel that links the new thread to the main thread
150 const {
151 port1: mainThreadPortToMain,
152 port2: mainThreadPortToThread,
153 } = new MessageChannel();
154
155 const registrationMessage = {
156 type: messageTypes.REGISTER_MAIN_THREAD_PORT,
157 threadId,
158 port: mainThreadPortToMain,
159 };
160
161 if (isMainThread) {
162 handleMessageFromThread(registrationMessage);
163 } else {
164 mainThreadPort.postMessage(registrationMessage, [mainThreadPortToMain]);
165 }
166
167 return mainThreadPortToThread;
168}
169
170function destroyMainThreadPort(threadId) {
171 const unregistrationMessage = {

Callers 1

constructorMethod · 0.85

Calls 2

handleMessageFromThreadFunction · 0.85
postMessageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…