From e1a9d21254494718ebf97720924bc8f9dc4e6bff Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Fri, 9 Aug 2019 11:07:54 +0200 Subject: [PATCH] :bug: Fix bug that child process did exit before message got sent --- packages/cli/src/WorkflowRunnerProcess.ts | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/WorkflowRunnerProcess.ts b/packages/cli/src/WorkflowRunnerProcess.ts index d5d6c3f4b..0c631dc95 100644 --- a/packages/cli/src/WorkflowRunnerProcess.ts +++ b/packages/cli/src/WorkflowRunnerProcess.ts @@ -133,11 +133,20 @@ export class WorkflowRunnerProcess { * * @param {string} type The type of data to send * @param {*} data The data + * @returns {Promise} */ -function sendToParentProcess(type: string, data: any): void { // tslint:disable-line:no-any - process.send!({ - type, - data, +async function sendToParentProcess(type: string, data: any): Promise { // tslint:disable-line:no-any + return new Promise((resolve, reject) => { + process.send!({ + type, + data, + }, (error: Error) => { + if (error) { + return reject(error); + } + + resolve(); + }); }); } @@ -152,7 +161,7 @@ process.on('message', async (message: IProcessMessage) => { if (message.type === 'startWorkflow') { const runData = await workflowRunner.runWorkflow(message.data); - sendToParentProcess('end', { + await sendToParentProcess('end', { runData, }); @@ -186,7 +195,7 @@ process.on('message', async (message: IProcessMessage) => { workflowRunner.sendHookToParentProcess('workflowExecuteAfter', [fullRunData]); } - sendToParentProcess('end', { + await sendToParentProcess('end', { fullRunData, }); @@ -200,9 +209,9 @@ process.on('message', async (message: IProcessMessage) => { stack: error.stack, } as IExecutionError; - sendToParentProcess('processError', { + await sendToParentProcess('processError', { executionError, }); process.exit(); } -}); \ No newline at end of file +});