Skip to content

Commit 9567aa3

Browse files
chore: fix benchmark result reporting (#16)
1 parent 17c4541 commit 9567aa3

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

packages/bson-bench/src/base.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,34 @@ import {
1212
type RunBenchmarkMessage
1313
} from './common';
1414

15-
function reportResultAndQuit(result: BenchmarkResult) {
16-
if (process.send) process?.send({ type: 'returnResult', result });
15+
function exit(code: number) {
1716
process.disconnect();
18-
process.exit(0);
17+
process.exit(code);
18+
}
19+
20+
function reportResultAndQuit(result: BenchmarkResult) {
21+
if (process.send) {
22+
process.send({ type: 'returnResult', result }, null, {}, () => exit(0));
23+
return;
24+
}
25+
exit(0);
1926
}
2027

2128
function reportErrorAndQuit(error: Error) {
22-
if (process.send)
23-
process.send({
24-
type: 'returnError',
25-
error
26-
});
27-
process.disconnect();
28-
process.exit(1);
29+
if (process.send) {
30+
process.send(
31+
{
32+
type: 'returnError',
33+
error
34+
},
35+
null,
36+
{},
37+
() => exit(0)
38+
);
39+
return;
40+
}
41+
42+
exit(1);
2943
}
3044

3145
function run(bson: BSONLib | ConstructibleBSON, config: BenchmarkSpecification) {

0 commit comments

Comments
 (0)