I have a situation where I want to run multiple EventMachines in Ruby - does anyone have experience with this? (I can write a test case to do it myself, if not. Stay with us).
Let's be clear: I want to create two threads myself and call EventMachine.run on both threads, so I really have two reactor loops.
The reason is because I am writing an asynchronous message bus with the AMQP gem that uses EventMachine. This is great, but I want to make it a separate modular component that can be used in two applications:
- which has its own gui lock cycle (which cannot be simulated by calling a tick from EventMachine - it really blocks, and it does this in the C library, so I can't crack it). It's simple: just start EM in your thread and share the incoming messages between loops in a thread-safe manner;
- and another application that itself works in the reactor loop, and I can share it with the AMQP code (which is good for thread safety problems), although I should still refer to the above application. This is what made me think ... Can I share the message bus code with the above application by running two separate EventMachines?
Anyone have any thoughts?
source share