Method: Net::SSH::Connection::Channel#on_process
- Defined in:
- lib/net/ssh/connection/channel.rb
#on_process(&block) ⇒ Object
Registers a callback to be invoked for each pass of the event loop for this channel. There are no guarantees on timeliness in the event loop, but it will be called roughly once for each packet received by the connection (not the channel). This callback is invoked with the channel as the sole argument.
Here’s an example that accumulates the channel data into a variable on the channel itself, and displays individual lines in the input one at a time when the channel is processed:
channel[:data] = ""
channel.on_data do |ch, data|
channel[:data] << data
end
channel.on_process do |ch|
if channel[:data] =~ /^.*?\n/
puts $&
channel[:data] = $'
end
end
372 373 374 375 |
# File 'lib/net/ssh/connection/channel.rb', line 372 def on_process(&block) old, @on_process = @on_process, block old end |