EventMachine:我似乎无法将args传递给Server的构造函数(通过start_server)或通过块

时间:2016-05-03 15:27:27

标签: ruby eventmachine

我想用一个参数初始化一个EventMachine服务器,但是我很难这样做。

我有这个启动服务器的代码:

port = APP_CONFIG.user['port']
Display.info "listening on port #{port}"
EM.start_server('0.0.0.0', port, Network::Local::Server) do |server|
  server.prepare(_message_dispatcher)
end

我希望在这个类上调用prepare

  module Network
    module Local
      class Server < EM::Connection
        include EM::HttpServer
        attr_reader :_message_dispatcher, :_request_processor

        def prepare(message_dispatcher) # or initialize(message_dispatcher)
          puts 'hi'
          @_message_dispatcher = message_dispatcher
          @_request_processor = Decryption::RequestProcessor.new(
            network: NETWORK_LOCAL,
            message_dispatcher: message_dispatcher)
          puts 'done'
        end
        # ....

但看跌期权永远不会输出到控制台。但是,在我致电listening on port 8009

之前,我确实会看到EM.start_server

我也试过这个:

EM.start_server('0.0.0.0', port,
  Network::Local::Server, _message_dispatcher)

然后将我的prepare方法更改为initialize,但我得到了相同的结果。看跌期权未显示在控制台中,但我看到listening on port 8009

我做错了什么?

0 个答案:

没有答案