Class: TTYProcessCtl::Listener
- Inherits:
-
Object
- Object
- TTYProcessCtl::Listener
- Defined in:
- lib/tty-process-ctl.rb
Instance Method Summary collapse
- #call(message) ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(&callback) ⇒ Listener
constructor
A new instance of Listener.
- #on_close(&callback) ⇒ Object
Constructor Details
#initialize(&callback) ⇒ Listener
Returns a new instance of Listener.
10 11 12 |
# File 'lib/tty-process-ctl.rb', line 10 def initialize(&callback) @callback = callback end |
Instance Method Details
#call(message) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/tty-process-ctl.rb', line 14 def call() @callback.call() rescue LocalJumpError => error # brake in listener close if error.reason == :break end |
#close ⇒ Object
26 27 28 29 |
# File 'lib/tty-process-ctl.rb', line 26 def close @on_close.call(self) if @on_close @closed = true end |
#closed? ⇒ Boolean
31 32 33 |
# File 'lib/tty-process-ctl.rb', line 31 def closed? @closed end |
#on_close(&callback) ⇒ Object
21 22 23 24 |
# File 'lib/tty-process-ctl.rb', line 21 def on_close(&callback) @on_close = callback unless closed? self end |