Skip to content

Commit

Permalink
fix: Child processes are cleaned up when useChildProcesses is used
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardMcfly committed Jun 1, 2021
1 parent b320b18 commit 3fb5b69
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path'
import path from 'path'
import { node } from 'execa'

const childProcessHelperPath = resolve(__dirname, 'childProcessHelper.js')
const childProcessHelperPath = path.resolve(__dirname, 'childProcessHelper.js')

export default class ChildProcessRunner {
#env = null
Expand Down Expand Up @@ -36,19 +36,22 @@ export default class ChildProcessRunner {
},
)

const message = new Promise((resolve, reject) => {
childProcess.on('message', (data) => {
if (data.error) reject(data.error)
else resolve(data)
})
}).finally(() => {
childProcess.kill()
})

childProcess.send({
context,
event,
allowCache: this.#allowCache,
timeout: this.#timeout,
})

const message = new Promise((_resolve) => {
childProcess.on('message', _resolve)
// TODO
// on error? on exit? ..
})

let result

try {
Expand Down

0 comments on commit 3fb5b69

Please sign in to comment.