Method: Net::SSH::Connection::Session#process

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

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

The core of the event loop. It processes a single iteration of the event loop. If a block is given, it should return false when the processing should abort, which causes #process to return false. Otherwise, #process returns true. The session itself is yielded to the block as its only argument.

If wait is nil (the default), this method will block until any of the monitored IO objects are ready to be read from or written to. If you want it to not block, you can pass 0, or you can pass any other numeric value to indicate that it should block for no more than that many seconds. Passing 0 is a good way to poll the connection, but if you do it too frequently it can make your CPU quite busy!

This will also cause all active channels to be processed once each (see Net::SSH::Connection::Channel#on_process).

TODO revise example

process multiple Net::SSH connections in parallel

connections = [ Net::SSH.start("host1", ...), Net::SSH.start("host2", ...) ]

connections.each do |ssh|
ssh.exec "grep something /in/some/files"
end

condition = Proc.new { |s| s.busy? }

loop do
connections.delete_if { |ssh| !ssh.process(0.1, &condition) }
break if connections.empty?
end


215
216
217
218
219
220
# File 'lib/net/ssh/connection/session.rb', line 215

def process(wait=nil, &block)
  @event_loop.process(wait, &block)
rescue
  force_channel_cleanup_on_close if closed?
  raise
end