Method: Net::SSH::Connection::Session#loop

Defined in:
lib/net/ssh/connection/session.rb

#loop(wait = nil, &block) ⇒ Object

The main event loop. Calls #process until #process returns false. If a block is given, it is passed to #process, otherwise a default proc is used that just returns true if there are any channels active (see #busy?). The # wait parameter is also passed through to #process (where it is interpreted as the maximum number of seconds to wait for IO.select to return).

# loop for as long as there are any channels active
ssh.loop

# loop for as long as there are any channels active, but make sure
# the event loop runs at least once per 0.1 second
ssh.loop(0.1)

# loop until ctrl-C is pressed
int_pressed = false
trap("INT") { int_pressed = true }
ssh.loop(0.1) { not int_pressed }


162
163
164
165
# File 'lib/net/ssh/connection/session.rb', line 162

def loop(wait=nil, &block)
  running = block || Proc.new { busy? }
  loop_forever { break unless process(wait, &running) }
end