This commit is contained in:
2026-01-25 21:19:28 +08:00
parent 3284a06ad5
commit 8a1aff4c50
2 changed files with 6 additions and 4 deletions

View File

@@ -614,7 +614,8 @@ export class QueryRouter {
}
/**
* 等待程序运行, 获取到message的数据,就执行
*
* params 是预设参数默认path为main
*
* emitter = process
* -- .exit
* -- .on

View File

@@ -2,7 +2,7 @@ export type ListenProcessOptions = {
app?: any; // 传入的应用实例
emitter?: any; // 可选的事件发射器
params?: any; // 可选的参数
timeout?: number; // 可选的超时时间 (单位: 毫秒)
timeout?: number; // 可选的超时时间 (单位: 毫秒) 默认 10 分钟
};
export const listenProcess = async ({ app, emitter, params, timeout = 10 * 60 * 60 * 1000 }: ListenProcessOptions) => {
const process = emitter || globalThis.process;
@@ -27,9 +27,10 @@ export const listenProcess = async ({ app, emitter, params, timeout = 10 * 60 *
}
try {
const { path = 'main', ...rest } = await getParams()
const { path = 'main', payload = {}, ...rest
} = await getParams()
// 执行主要逻辑
const result = await app.queryRoute({ path, ...rest, ...params })
const result = await app.queryRoute({ path, ...params, ...rest, payload: { ...params.payload, ...payload } })
// 发送结果回主进程
const response = {
success: true,