开发者

Possible to use EM calls in a Thin webapp?

开发者 https://www.devze.com 2023-03-17 04:48 出处:网络
Is i开发者_运维百科t possible to use EventMachine calls inside Thin without extra initialization?

Is i开发者_运维百科t possible to use EventMachine calls inside Thin without extra initialization?

Currently, I have a Sinatra app run by Thin (which is running as a service). When I try to use EventMachine.connect_unix_domain, I get eventmachine not initialized... even though Thin (and presumably EventMachine) is running.

class App < Sinatra::Base
  $sock = EventMachine.connect_unix_domain("/tmp/appsock.sock")
  # import all routes
  Dir.glob("controllers/*.rb").each { |r| require_relative r }
end


My guess (sorry, don't have em installed on this box) is that the issue is because the code will be evaluated when the class is loaded. At that point, thin probably isn't setup and EM probably isn't initialized.

You could try wrapping the $sock = ... call in an EM.next_tick {} which should delay the execution until EM has actually started.

I believe, if memory serves, you can add stuff to next_tick before EM is actually initialized.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号