methods.js
This file
Path
lib/ipc/methods.js
49 lines · 1.2 KiB · JavaScript
Last changed by
Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import process from 'node:process';import {sendMessage} from './send.js';import {getOneMessage} from './get-one.js';import {getEachMessage} from './get-each.js';import {getCancelSignal} from './graceful.js';
// Add promise-based IPC methods in current processexport const addIpcMethods = (subprocess, {ipc}) => { Object.assign(subprocess, getIpcMethods(subprocess, false, ipc));};
// Get promise-based IPC in the subprocessexport const getIpcExport = () => { const anyProcess = process; const isSubprocess = true; const ipc = process.channel !== undefined;
return { ...getIpcMethods(anyProcess, isSubprocess, ipc), getCancelSignal: getCancelSignal.bind(undefined, { anyProcess, channel: anyProcess.channel, isSubprocess, ipc, }), };};
// Retrieve the `ipc` shared by both the current process and the subprocessconst getIpcMethods = (anyProcess, isSubprocess, ipc) => ({ sendMessage: sendMessage.bind(undefined, { anyProcess, channel: anyProcess.channel, isSubprocess, ipc, }), getOneMessage: getOneMessage.bind(undefined, { anyProcess, channel: anyProcess.channel, isSubprocess, ipc, }), getEachMessage: getEachMessage.bind(undefined, { anyProcess, channel: anyProcess.channel, isSubprocess, ipc, }),});