How to communicate with threads in Ruby?

丶灬走出姿态 提交于 2019-12-17 20:26:27

问题


I'm building a real time game, mostly chat based, and I need to have many of these chats running concurrently, receiving and sending data through web sockets.

I have been told that instead of spawning one process per game, I should have one process with one thread per game (maybe using Event Machine).

I'm using Juggernaut for the sockets part, it lets me send data to all the players in a game by using a publish/subscribe system: each player subscribes to one game. But how do I send data from each player to that particular game?

I was thinking that I could send the game ID or channel ID from the client to the server, and then send it to the corresponding thread.

But how do I send anything to a thread?


回答1:


To send data to a thread, you can use Ruby Queue:

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/thread/rdoc/Queue.html



来源:https://stackoverflow.com/questions/10045693/how-to-communicate-with-threads-in-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!