hedwig-im/hedwig

Make Robot a real OTP behaviour

michalmuskala opened this issue · 4 comments

Currently the Hewdig.Robot module masquerades as a pseudo behaviour through macros and injection of code into the user's module. This has couple issues, most notably the robot cannot be started twice - for example with different adapters - to handle traffic from two different networks. This limitation prevents me from using the library in it's current shape.

The Hedwig.Robot should be made a real behaviour with API similar to GenServer or to the custom Connection behaviour. This would make the code more flexible for runtime changes and configuration. Limiting injecting code into user modules should also speed up compilation. It is generally discouraged to inject large amounts of code into user modules.

If you agree this would be beneficial I would be glad to work on this.

@michalmuskala - Yes I agree. I have thought about this many many times.

I appreciate your willingness to help, but this would be something I would prefer to do myself as I have been wanting to do for a while now.

I would definitely appreciate feedback though. Sound good?

I totally understand that. If you have some questions or code you'd like me to review, just ping me.

I sure will. Thanks for understanding.

I'm going to release v1.0.0 and then begin on this change for 2.0.

I'd love to see this for 2.0 as well. I just ran into another issue that stems from this, where a race condition exists due to the global name registration being deferred until handle_connect in the Robot behavior. Ideally this would be in start_link but that function is part of the code being injected and can't be overridden. I'd even settle for init but it's also being injected.