Method: EventMachine.connection_count

Defined in:
lib/eventmachine.rb

.connection_countInteger

Returns the total number of connections (file descriptors) currently held by the reactor. Note that a tick must pass after the 'initiation' of a connection for this number to increment. It's usually accurate, but don't rely on the exact precision of this number unless you really know EM internals.

Examples:


EventMachine.run {
  EventMachine.connect("rubyeventmachine.com", 80)
  # count will be 0 in this case, because connection is not
  # established yet
  count = EventMachine.connection_count
}

EventMachine.run {
  EventMachine.connect("rubyeventmachine.com", 80)

  EventMachine.next_tick {
    # In this example, count will be 1 since the connection has been established in
    # the next loop of the reactor.
    count = EventMachine.connection_count
  }
}

Returns:

  • (Integer)

    Number of connections currently held by the reactor.



945
946
947
# File 'lib/eventmachine.rb', line 945

def self.connection_count
  self.get_connection_count
end