buffer-messages.js
This file
Path
lib/ipc/buffer-messages.js
57 lines · 1.3 KiB · JavaScript
Last changed by
Fix `verbose` discarding IPC messages when its function throwsSindre Sorhusbefore adoptionb548d8b
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import {checkIpcMaxBuffer} from '../io/max-buffer.js';import {shouldLogIpc, logIpcOutput} from '../verbose/ipc.js';import {getFdSpecificValue} from '../arguments/specific.js';import {loopOnMessages} from './get-each.js';
// Iterate through IPC messages sent by the subprocessexport const waitForIpcOutput = async ({ subprocess, buffer: bufferArray, maxBuffer: maxBufferArray, ipc, ipcOutput, verboseInfo,}) => { if (!ipc) { return ipcOutput; }
const isVerbose = shouldLogIpc(verboseInfo); const buffer = getFdSpecificValue(bufferArray, 'ipc'); const maxBuffer = getFdSpecificValue(maxBufferArray, 'ipc'); // A throwing `verbose` function must not prevent the following messages from being buffered const logErrors = [];
for await (const message of loopOnMessages({ anyProcess: subprocess, channel: subprocess.channel, isSubprocess: false, ipc, shouldAwait: false, reference: true, })) { if (buffer) { checkIpcMaxBuffer(ipcOutput, maxBuffer); ipcOutput.push(message); }
if (isVerbose) { try { logIpcOutput(message, verboseInfo); } catch (error) { logErrors.push(error); } } }
if (logErrors.length > 0) { throw logErrors[0]; }
return ipcOutput;};
export const getBufferedIpcOutput = async (ipcOutputPromise, ipcOutput) => { await Promise.allSettled([ipcOutputPromise]); return ipcOutput;};