Class: Net::SSH::Connection::Channel
- Inherits:
-
Object
- Object
- Net::SSH::Connection::Channel
- Defined in:
- lib/evented-ssh/connection/channel.rb
Instance Attribute Summary collapse
-
#defer ⇒ Object
readonly
Returns the value of attribute defer.
Instance Method Summary collapse
- #close ⇒ Object
- #do_close ⇒ Object
-
#initialize(connection, *args, &block) ⇒ Channel
constructor
A new instance of Channel.
- #original_do_close ⇒ Object
- #original_initialize ⇒ Object
- #original_send_data ⇒ Object
-
#promise ⇒ Object
Allow direct access to the promise.
- #send_data(data) ⇒ Object
-
#wait ⇒ Object
Use promise resolution instead of a loop.
Constructor Details
#initialize(connection, *args, &block) ⇒ Channel
Returns a new instance of Channel.
7 8 9 10 11 12 13 14 15 |
# File 'lib/evented-ssh/connection/channel.rb', line 7 def initialize(connection, *args, &block) original_initialize(connection, *args, &block) @defer = connection.transport.reactor.defer # Cleanup channel when it closes @defer.promise.finally { process } end |
Instance Attribute Details
#defer ⇒ Object (readonly)
Returns the value of attribute defer.
17 18 19 |
# File 'lib/evented-ssh/connection/channel.rb', line 17 def defer @defer end |
Instance Method Details
#close ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/evented-ssh/connection/channel.rb', line 44 def close return if @closing @closing = true # Actively attempt to close the channel @connection.transport.reactor.next_tick do process end end |
#do_close ⇒ Object
32 33 34 35 36 |
# File 'lib/evented-ssh/connection/channel.rb', line 32 def do_close # Resolve the promise and anything waiting @defer.resolve(nil) original_do_close end |
#original_do_close ⇒ Object
31 |
# File 'lib/evented-ssh/connection/channel.rb', line 31 alias_method :original_do_close, :do_close |
#original_initialize ⇒ Object
6 |
# File 'lib/evented-ssh/connection/channel.rb', line 6 alias_method :original_initialize, :initialize |
#original_send_data ⇒ Object
38 |
# File 'lib/evented-ssh/connection/channel.rb', line 38 alias_method :original_send_data, :send_data |
#promise ⇒ Object
Allow direct access to the promise. Means we can do parallel tasks and then grab the results of multiple executions.
27 28 29 |
# File 'lib/evented-ssh/connection/channel.rb', line 27 def promise @defer.promise end |
#send_data(data) ⇒ Object
39 40 41 42 |
# File 'lib/evented-ssh/connection/channel.rb', line 39 def send_data(data) original_send_data(data) process end |
#wait ⇒ Object
Use promise resolution instead of a loop
20 21 22 |
# File 'lib/evented-ssh/connection/channel.rb', line 20 def wait @defer.promise.value end |