Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case that backpressure lose consistency after error happens #45

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "caminho",
"version": "1.7.0",
"version": "1.7.1",
"description": "Tool for creating efficient data pipelines in a JavaScript environment",
"main": "./dist/cjs/index.js",
"module": "./dist/esm5/index.js",
Expand Down Expand Up @@ -72,4 +72,4 @@
"dependencies": {
"rxjs": "^7.8.1"
}
}
}
2 changes: 1 addition & 1 deletion src/Caminho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Caminho implements CaminhoInterface {
const loggers = this.getLoggers(generatorParams)
if (this.options?.maxItemsFlowing) {
const pendingDataControl = this.pendingDataControl as PendingDataControl
this.finalStep = tap(() => pendingDataControl.decrement())
this.finalStep = tap({ next: () => pendingDataControl.decrement(), error: () => pendingDataControl.decrement() })
return wrapGeneratorWithBackPressure(generatorParams, this.options.maxItemsFlowing, pendingDataControl, loggers)
}

Expand Down
9 changes: 9 additions & 0 deletions test/integration/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ describe('Error Handling', () => {

await expect(caminho.run()).rejects.toMatchObject({ message: 'Reduce error' })
})

test('Should not interfere with the backpressure when error happens', async () => {
const operator = jest.fn().mockRejectedValueOnce(new Error('Operator error')).mockResolvedValue(null)
const caminho = fromGenerator({ fn: getMockedGenerator([1, 2]), provides: 'number' }, { maxItemsFlowing: 1 })
.pipe({ fn: operator })

await expect(caminho.run()).rejects.toMatchObject({ message: 'Operator error' })
expect(caminho.getNumberOfItemsFlowing()).toBe(0)
})
})
Loading