Skip to content

Commit ba9529e

Browse files
committed
cache response message on exit
1 parent 3bd7375 commit ba9529e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lib/internal/modules/esm/worker.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,21 @@ async function customizedModuleWorker(lock, syncCommPort, errorHandler) {
9898
// so it can detect the exit event.
9999
const { exit } = process;
100100
process.exit = function(code) {
101+
const exitMsg = wrapMessage('exit', code ?? process.exitCode);
101102
if (hooks) {
102103
for (let i = 0; i < allThreadRegisteredHandlerPorts.length; i++) {
103104
const registeredPort = allThreadRegisteredHandlerPorts[i];
104-
registeredPort.postMessage(wrapMessage('exit', code ?? process.exitCode));
105+
registeredPort.postMessage(exitMsg);
105106
}
106107

107108
for (const { port, lock: operationLock } of unsettledResponsePorts) {
108-
port.postMessage(wrapMessage('exit', code ?? process.exitCode));
109+
port.postMessage(exitMsg);
109110
// Wake all threads that have pending operations. Is that needed???
110111
AtomicsAdd(operationLock, WORKER_TO_MAIN_THREAD_NOTIFICATION, 1);
111112
AtomicsNotify(operationLock, WORKER_TO_MAIN_THREAD_NOTIFICATION);
112113
}
113114
}
114-
syncCommPort.postMessage(wrapMessage('exit', code ?? process.exitCode));
115+
syncCommPort.postMessage(exitMsg);
115116
AtomicsAdd(lock, WORKER_TO_MAIN_THREAD_NOTIFICATION, 1);
116117
AtomicsNotify(lock, WORKER_TO_MAIN_THREAD_NOTIFICATION);
117118
return ReflectApply(exit, this, arguments);
@@ -185,7 +186,7 @@ async function customizedModuleWorker(lock, syncCommPort, errorHandler) {
185186
/**
186187
* @callback registerHandler
187188
* @param {MessagePort} toWorkerThread - Upon Worker creation a message channel between the new Worker
188-
* and the Hooks thread is bein initialized. This is the message part that the Hooks thread will use post
189+
* and the Hooks thread is being initialized. This is the MessagePort that the Hooks thread will use post
189190
* messages to the worker. The other MessagePort is passed to the new Worker itself via LOAD_SCRIPT message
190191
*/
191192
function registerHandler(toWorkerThread) {

0 commit comments

Comments
 (0)