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

Function handleMessageFromThread

lib/internal/worker/messaging.js:58–90  ·  view source on GitHub ↗
(message)

Source from the content-addressed store, hash-verified

56
57// This event handler is always executed on the main thread only
58function handleMessageFromThread(message) {
59 switch (message.type) {
60 case messageTypes.REGISTER_MAIN_THREAD_PORT:
61 {
62 const { threadId, port } = message;
63
64 // Register the port
65 threadsPorts.set(threadId, port);
66
67 // Handle messages on this port
68 // When a new thread wants to register a children
69 // this take care of doing that.
70 // This way any thread can be linked to the main one.
71 port.on('message', handleMessageFromThread);
72
73 // Never block the thread on this port
74 port.unref();
75 }
76
77 break;
78 case messageTypes.UNREGISTER_MAIN_THREAD_PORT:
79 threadsPorts.get(message.threadId).close();
80 threadsPorts.delete(message.threadId);
81 break;
82 case messageTypes.SEND_MESSAGE_TO_WORKER:
83 {
84 // Send the message to the target thread
85 const { source, destination, value, transferList, memory } = message;
86 sendMessageToWorker(source, destination, value, transferList, memory);
87 }
88 break;
89 }
90}
91
92function handleMessageFromMainThread(message) {
93 switch (message.type) {

Callers 3

createMainThreadPortFunction · 0.85
destroyMainThreadPortFunction · 0.85
postMessageToThreadFunction · 0.85

Calls 7

sendMessageToWorkerFunction · 0.85
closeMethod · 0.65
getMethod · 0.65
deleteMethod · 0.65
setMethod · 0.45
onMethod · 0.45
unrefMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…