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

前端 未结 8 1919
星月不相逢
星月不相逢 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:40

    You cannot run the Eventmachine engine inside of Rails itself as it is a persistent run loop that would block one of your Rails processes permanently. What is usually done is there's a side-process that uses Eventmachine and Rails communicates with it through sockets to send notifications.

    Juggernaut serves as an example of this kind of thing where it implements a Websocket client and a Rails hook to send notifications to it. The project has since deprecated the Ruby version in favor of a JavaScript Node.js version but this still serves as a very thorough example of how Eventmachine can be used.

提交回复
热议问题