Refactor connection lifecycle for asynchronous sessions contexts#27
Open
michaelosthege wants to merge 5 commits intoCommonplaceRobotics:masterfrom
Open
Refactor connection lifecycle for asynchronous sessions contexts#27michaelosthege wants to merge 5 commits intoCommonplaceRobotics:masterfrom
michaelosthege wants to merge 5 commits intoCommonplaceRobotics:masterfrom
Conversation
This way one can create a client with only non-dangerous read methods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This replaces #26 where I tried to work around an issue that I ran into due to unclean connect/disconnect/dispose resource management when connections failed.
Essentially the threads must be regarded as "single use", but this requires them to be recreated if the same
CRIControllershould be re-used.Even more convenient would be a context manager that deals with proper disconnects and resource disposal, regardless of user level implementation.
Based on my comment here I refactored in the following way:
connectis changed toraiseon errors -- this is a breaking change, but it's much easier to work with as it enables passing contextual information up the stack (through exception types and messages) which is not the case withreturn False.CRIControllerclass is split intoCRIClientandCRIController(CRIClient)which makes it possible to separate observational and actuating code based on type information.CRIConnectoris introduced: This is a factory-like creator of connection session contexts.asynccontext managers.I also added an example that uses the
CRIConnectorcontexts.This asynchronous context manager style connection is relevant for us for multiple reasons:
CRIClientcan be long-lived, auto-reconnectiing to monitor whileCRIControlleris only invoked for movementWhat do you think, @cpr-bar ?