Class: EventMachine::EmStartStopTimeouts::ServersManipulationQueue
- Defined in:
- lib/emrpc/util/em_start_stop_timeouts.rb
Instance Method Summary collapse
-
#initialize ⇒ ServersManipulationQueue
constructor
A new instance of ServersManipulationQueue.
- #start_server(host, port, *args, &blk) ⇒ Object
- #stop_server(s, *args, &blk) ⇒ Object
Constructor Details
#initialize ⇒ ServersManipulationQueue
Returns a new instance of ServersManipulationQueue.
22 23 24 25 26 |
# File 'lib/emrpc/util/em_start_stop_timeouts.rb', line 22 def initialize @ports = {} @signs = {} @em = EventMachine end |
Instance Method Details
#start_server(host, port, *args, &blk) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/emrpc/util/em_start_stop_timeouts.rb', line 28 def start_server(host, port, *args, &blk) if @ports[port] sleep 0.1 if Time.now - @ports[port][1] < 1 s = @ports[port].first @ports[port] = nil @signs[s] = nil end s = @em.non_queued_start_server(host, port, *args, &blk) @ports[port] = [s, Time.now] @signs[s] = port s end |
#stop_server(s, *args, &blk) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/emrpc/util/em_start_stop_timeouts.rb', line 41 def stop_server(s, *args, &blk) port = @signs[s] sleep 0.1 if port && Time.now - @ports[port][1] < 1 r = @em.non_queued_stop_server(s, *args, &blk) @ports[port] = [s, Time.now] if port r end |