如何/在哪里保存 EventMachine 对象?
我正在尝试编写一个应用程序,该应用程序从视图读取数据并使用控制器与 EventMachine 实例进行通信(从通道中放入/获取数据)。
我现在的设计是保留 EventMachine 反应器和字典 其中包含事件机器循环的 ID 以及对通道输入/输出的引用。事件循环将连接到 IRC 服务器并获取/发送由前端驱动的请求。
目前,我有一个视图将发布到引用固定事件机 (@@myeventmachine) 和我在初始化程序中定义的连接字典 (@@connections) 的控制器。现在的问题似乎是控制器/视图在单次执行后被释放,因此我无法在其中存储连接状态(或者我可以吗?)。
在应用程序中拥有全局性的整个想法让我感到畏缩,所以我想知道是否有更好的、更“类似轨道”的方式来保存这些信息。这是我的第一个 Rails/Ruby 项目,所以我在这里有点迷失。我发现的大部分信息涉及如何使用 EventMachine 的异步特性,而不是如何在视图/控制器的多个实例中持久保存反应器/通道。
I'm trying to write an application that reads data from a View and uses a controller to communicate (put / get data from a channel) with an EventMachine instance.
The design I have right now is that I will persist the EventMachine reactor and a dictionary
that contains the ID for the event machine loop and references to the channel in/out. The event loop will connect to an IRC server and get/send requests driven by the front end.
Currently I have a view that will post to a controller that references a fixed event machine (@@myeventmachine) and a dictionary of connections (@@connections) that I defined in an initializer. The problem now seems to be that the controller/view are disposed after a single execution so I cannot store connection state in it (or can I?).
The whole idea of having something global in the application is making me cringe though, so I wonder if there's a better, more "rails like" way of persisting that information. This is my first rails/ruby project so I'm a bit lost here. Most of the information I found deals with how to use the asynchronous nature of EventMachine, and not how to persist the reactor/channels across many instances of the view/controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论