(message)
| 56 | |
| 57 | // This event handler is always executed on the main thread only |
| 58 | function 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 | |
| 92 | function handleMessageFromMainThread(message) { |
| 93 | switch (message.type) { |
no test coverage detected
searching dependent graphs…