Combined 子进程 | IPC 协议 | 事件通道 | 生命周期 | 错误处理 | Electron 集成
想系统学习 Node 的“进程/线程/事件循环/Worker/Cluster/Child Process”等知识? 点此进入《Node 进程与线程实战手册》
蓝色箭头:IPC 请求/响应。左侧为主服务(VFService + CombinedManager + SocketIO),右侧为合并后的子进程。
{ id: string, type: 'init' | 'task' | 'shutdown', payload?: any }
// init.payload: { enginePath, flightsimDllPath, analysisDllPath }
// task.payload: { taskName, parameter }
// events(无 id): { event: 'closedEngine', closedPID } | { event: 'callback', uid, data }
子进程严格串行处理,确保原生库非线程安全部分不被并发访问。
// 引擎类(部分)
openFlightSimEngine({ enginePath, showEngine }) → engineId
closeFlightSimEngine({ engineId }) → boolean
loadPrj({ engineId, prjPath }) → boolean
runModel({ engineId, modelId }) → any
// 分析类(部分)
startProjectMonteCarloSim({ engineIds, engineNames, parameter, uid })
startProjectMinDuFenXi({ ... }) / startProjectOptimization({ ... })
// VFService 常用
acquireInstance(key, ownerId?) → rec
openFlightSimEngine(key, show?) → engineId
closeFlightSimEngine({ key, engineId }) → ok
getDefaultEngineHandle({ key }) → engineId | null
// 1) 直接使用 CombinedManager(Node 环境)
import { CombinedManager } from './dist/process/combinedManager.fork.js';
const mgr = new CombinedManager('C:/Path/To/VFlight.exe');
const engineId = await mgr.send('openFlightSimEngine', { enginePath: 'C:/Path/To/VFlight.exe', showEngine: false });
await mgr.send('loadPrj', { engineId, prjPath: 'C:/Path/To/solution.prjt' });
// 2) VFService(应用内)
await vfService.initVFService({ enginePath: 'C:/Path/To/VFlight.exe' });
await vfService.acquireInstance(123);
const eid = await vfService.openFlightSimEngine(123, false);
await vfService.loadPrj({ key: 123, engineId: eid, prjtPath: '.../solution.prjt' });
提示:示例路径需替换为部署环境实际路径。
© 本页用于进程管理模块学习与上手速览。建议配合源码 src/process 与 src/service/vfnode.service.ts 阅读。