From 9567aa3dfca256ca9f15173823741622baa9ebb7 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Fri, 30 Aug 2024 13:02:25 -0600 Subject: [PATCH] chore: fix benchmark result reporting (#16) --- packages/bson-bench/src/base.ts | 34 +++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/bson-bench/src/base.ts b/packages/bson-bench/src/base.ts index 56dd1bd1..6012eab6 100644 --- a/packages/bson-bench/src/base.ts +++ b/packages/bson-bench/src/base.ts @@ -12,20 +12,34 @@ import { type RunBenchmarkMessage } from './common'; -function reportResultAndQuit(result: BenchmarkResult) { - if (process.send) process?.send({ type: 'returnResult', result }); +function exit(code: number) { process.disconnect(); - process.exit(0); + process.exit(code); +} + +function reportResultAndQuit(result: BenchmarkResult) { + if (process.send) { + process.send({ type: 'returnResult', result }, null, {}, () => exit(0)); + return; + } + exit(0); } function reportErrorAndQuit(error: Error) { - if (process.send) - process.send({ - type: 'returnError', - error - }); - process.disconnect(); - process.exit(1); + if (process.send) { + process.send( + { + type: 'returnError', + error + }, + null, + {}, + () => exit(0) + ); + return; + } + + exit(1); } function run(bson: BSONLib | ConstructibleBSON, config: BenchmarkSpecification) {