Flow control for async message consumers #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
first of all thanks for providing rosbag.js it really made my day ☀️
I'm dealing with rosbag files that exceed my heap space and want to perform async operations on the messages.
Since (IMHU) calling
bag.readMessagesprovides no means to slow down the producer I have to choose between dropping messages or running out of heap.As a resolve I added flow control via
bag.iterateMessages. It does almost exactly the same thing asbag.readMessagesbut it acts as async generator. That means the consumer can (if desired) halt and resume the reading process.In order to avoid code redundancies and minimise code changes, I rewired
readMessagesto invokeiterateMessagesmaintaining its original behavior.Documentation and one additional test case is included in this PR.
If I overlooked existing functionality that already provides flow control, please let me know, so that I can use that instead.
I also bumped the node engine version to 10+ because the existing test cases failed at lower versions.
Regards, Marc