Multiple Ruby EventMachines in one process: possible?

半世苍凉 提交于 2019-12-04 05:00:48

OK, digging into EM's docs, I see the body for EventMachine.run starts with this:

240:     if reactor_running?
241:       (b = blk || block) and b.call # next_tick(b)
242:     else
         ... start the reactor ...

This is awesome. It looks like, if you do EventMachine.run in multiple threads, it will schedule the second machine's definition - the block passed to "run" - on the reactor that is already running.

I love this library.

You answered yourself but I wanted to add my 2 cents without the horrible styling of comments.

# this will start the eventmachine reactor
EM::run do

  # do something

  # this will do nothing and the block passed to it will
  # just be executed directly
  EM::run do
    # do something else
  end

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