Skip to content

Commit

Permalink
fix: Number of statements for multiple generators (#63)
Browse files Browse the repository at this point in the history
When multiple generators are configured, the number of statements
reporting was that of only one of those generators, picked randomly
based on which generator ends first. Fix that by reporting the
total number of statements for all generators combined.
  • Loading branch information
ddeboer authored May 28, 2024
1 parent 49858ec commit b9f8d61
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/lib/Stage.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,18 @@ class Stage extends EventEmitter {
end: false,
format: 'N-Triples',
});
let quadCount = 0;

const generatorProcessedCounts = new Map<number, number>();
let quadsGenerated = 0;

const checkEnd = (iterationsIncoming: number, statements: number): void => {
const checkEnd = (iterationsIncoming: number): void => {
if (
![...generatorProcessedCounts].some(
([, processed]) => processed < iterationsIncoming
) &&
this.iteratorEnded
) {
this.emit('end', iterationsIncoming, statements);
this.emit('end', iterationsIncoming, quadsGenerated);
}
};

Expand All @@ -109,13 +108,12 @@ class Stage extends EventEmitter {
generator.on('data', quad => {
quadsGenerated++;
writer.addQuad(quad);
quadCount++;
this.emit('generatorResult', quadCount);
this.emit('generatorResult', quadsGenerated);
});

generator.on('end', (iterationsIncoming, statements, processed) => {
generatorProcessedCounts.set(index, processed);
checkEnd(iterationsIncoming, statements);
checkEnd(iterationsIncoming);
});

generator.on('error', e => {
Expand Down

0 comments on commit b9f8d61

Please sign in to comment.