Class: IRuby::Comm
- Inherits:
-
Object
- Object
- IRuby::Comm
- Defined in:
- lib/iruby/comm.rb
Overview
Comm is a new messaging system for bidirectional communication. Both kernel and front-end listens for messages.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #close(**data) ⇒ Object
- #handle_close(data) ⇒ Object
- #handle_msg(data) ⇒ Object
-
#initialize(target_name, comm_id = SecureRandom.uuid) ⇒ Comm
constructor
A new instance of Comm.
- #open(**data) ⇒ Object
- #send(**data) ⇒ Object
Constructor Details
#initialize(target_name, comm_id = SecureRandom.uuid) ⇒ Comm
Returns a new instance of Comm.
12 13 14 |
# File 'lib/iruby/comm.rb', line 12 def initialize(target_name, comm_id = SecureRandom.uuid) @target_name, @comm_id = target_name, comm_id end |
Instance Attribute Details
#on_close(&b) ⇒ Object
34 35 36 |
# File 'lib/iruby/comm.rb', line 34 def on_close(&b) @on_close = b end |
#on_msg(&b) ⇒ Object
30 31 32 |
# File 'lib/iruby/comm.rb', line 30 def on_msg(&b) @on_msg = b end |
Class Method Details
.comm ⇒ Object
9 |
# File 'lib/iruby/comm.rb', line 9 def comm; @comm ||= {} end |
.target ⇒ Object
8 |
# File 'lib/iruby/comm.rb', line 8 def target; @target ||= {} end |
Instance Method Details
#close(**data) ⇒ Object
25 26 27 28 |
# File 'lib/iruby/comm.rb', line 25 def close(**data) Kernel.instance.session.send(:publish, :comm_close, comm_id: @comm_id, data: data) Comm.comm.delete(@comm_id) end |
#handle_close(data) ⇒ Object
42 43 44 |
# File 'lib/iruby/comm.rb', line 42 def handle_close(data) @on_close.call(data) if @on_close end |
#handle_msg(data) ⇒ Object
38 39 40 |
# File 'lib/iruby/comm.rb', line 38 def handle_msg(data) @on_msg.call(data) if @on_msg end |