From df0c4743b32cca58def9a0d6f52b658908d25652 Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Sat, 13 Aug 2022 08:47:22 -0400 Subject: [PATCH] refactor: make handler process private --- .../python-runner/PythonRunner.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/lambda/handler-runner/python-runner/PythonRunner.js b/src/lambda/handler-runner/python-runner/PythonRunner.js index a68f9948c..040ab428b 100644 --- a/src/lambda/handler-runner/python-runner/PythonRunner.js +++ b/src/lambda/handler-runner/python-runner/PythonRunner.js @@ -17,6 +17,8 @@ export default class PythonRunner { #env = null + #handlerProcess = null + #runtime = null constructor(funOptions, env) { @@ -38,7 +40,7 @@ export default class PythonRunner { const [pythonExecutable] = this.#runtime.split('.') - this.handlerProcess = spawn( + this.#handlerProcess = spawn( pythonExecutable, [ '-u', @@ -52,14 +54,14 @@ export default class PythonRunner { }, ) - this.handlerProcess.stdout.readline = createInterface({ - input: this.handlerProcess.stdout, + this.#handlerProcess.stdout.readline = createInterface({ + input: this.#handlerProcess.stdout, }) } // () => void cleanup() { - this.handlerProcess.kill() + this.#handlerProcess.kill() } #parsePayload(value) { @@ -113,8 +115,8 @@ export default class PythonRunner { try { const parsed = this.#parsePayload(line.toString()) if (parsed) { - this.handlerProcess.stdout.readline.removeListener('line', onLine) - this.handlerProcess.stderr.removeListener('data', onErr) + this.#handlerProcess.stdout.readline.removeListener('line', onLine) + this.#handlerProcess.stderr.removeListener('data', onErr) return accept(parsed) } return null @@ -123,12 +125,12 @@ export default class PythonRunner { } } - this.handlerProcess.stdout.readline.on('line', onLine) - this.handlerProcess.stderr.on('data', onErr) + this.#handlerProcess.stdout.readline.on('line', onLine) + this.#handlerProcess.stderr.on('data', onErr) process.nextTick(() => { - this.handlerProcess.stdin.write(input) - this.handlerProcess.stdin.write('\n') + this.#handlerProcess.stdin.write(input) + this.#handlerProcess.stdin.write('\n') }) }) }