How do you spawn an EventMachine “inside” a Rails app?

前端 未结 8 2098
星月不相逢
星月不相逢 2020-12-13 14:54

I\'ve got a Rails application, and am looking to add some sort of WebSocket support to it. From various googling, it appears that the best Ruby based WebSocket solution is

8条回答
  •  鱼传尺愫
    2020-12-13 15:16

    I'd try using em-synchrony to start a reactor in a fiber. In a rails app you can probably start it in an initializer since it sounds like you just want to leave the reactor running to respond to websocket requests. As suggested by the other answers I think you want to either setup socket communication with your reactor or use one of the asynchronous clients to a data store which both your reactor and rails code can read from and write to to exchange data.

    Some of my coworkers put together some examples of starting EM reactors on demand in ruby code to run their tests within EventMachine. I'd try using that as a possible example; raking and testing with eventmachine

提交回复
热议问题