Remove InputGuard, refactor test components without it#64
Conversation
|
@akokhanovskyi I agree Now that we are at it, I'd like to ask for your ideas about solving the original problem that The most typical situation is the following. We have some component Components like this are so common, that doing manual |
|
Right, staying low on reflection makes perfect sense. So far, the best option that comes to my mind is to provide some code generation tool that would reduce the amount of boilerplate to be written. I am not ready to comment on the functionality or usefulness of such a tool, though. On the other hand, could a few small examples illustrating typical use cases fit the bill as the MVP? I could use a few of those myself when starting with |
|
I tried to think of a solution on the weekend but could not come up with anything that would work without generics or reflection. I guess we can do with heavy boilerplate for now. As per examples, all I have currently is the tests and #53 which I'm using as a playground. This is all I can offer at this point, because my time to work on this project is very limited. |
Rationale:
InputGuardis unsafe to use; components for test provide a bad example.Explanation: The key problem is that after a channel is closed, it never blocks reads. The existing implementation leads to a dead
selectloop, which eventually exits whenselectrandomly chooses another execution branch. Updated component implementations provide a more accurate example of handling closed channels in go.Additionally, keeping a map of inputs is expensive and totally unnecessary, as it can be seen from the updated impl.
Finally, if we were to preserve
InputGuard-s for some reason, the implementation would have to be changed for safety. Consider what would happen if you accidentallyComplete()-d a non-existing port. What would happen if you accidentallyComplete()-d the same port twice?