Class: Net::SSH::Connection::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/evented-ssh/connection/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#deferObject (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

#closeObject



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_closeObject



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_closeObject



31
# File 'lib/evented-ssh/connection/channel.rb', line 31

alias_method :original_do_close, :do_close

#original_initializeObject



6
# File 'lib/evented-ssh/connection/channel.rb', line 6

alias_method :original_initialize, :initialize

#original_send_dataObject



38
# File 'lib/evented-ssh/connection/channel.rb', line 38

alias_method :original_send_data, :send_data

#promiseObject

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

#waitObject

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