【问题标题】:How to check if EventMachine::Connection is open?如何检查 EventMachine::Connection 是否打开?
【发布时间】:2012-06-22 04:23:32
【问题描述】:

我在事件机器中有一个 Connection 对象的句柄:http://eventmachine.rubyforge.org/EventMachine/Connection.html

如何检查连接在任何时间点是打开还是关闭? 我没有看到 API 中指定的任何方法。

【问题讨论】:

    标签: ruby eventmachine


    【解决方案1】:

    你必须自己实现它,这很容易。

    class SampleConnection < EM::Connection
      attr_accessor :connected
      def connection_completed
        connected = true
      end
    
      def connected?
        !!connected
      end
    
      def unbind
        connected = false
      end
    end
    

    【讨论】:

    • 是的,很容易自己实现。我想仔细检查一下课堂上没有现成的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多