Class: Neighborparrot::Reactor
- Inherits:
-
Object
- Object
- Neighborparrot::Reactor
- Includes:
- Neighborparrot
- Defined in:
- lib/neighborparrot/reactor.rb
Overview
Reactor class
Constant Summary
Constants included from Neighborparrot
Instance Method Summary collapse
-
#define_event_helpers ⇒ Object
generate events helpers for instances This define tho methods: on_event(&block): Setup a block for the event trigger_event(*args): Trigger the event.
-
#initialize ⇒ Reactor
constructor
Start the reactor in a new thead and prepare.
Methods included from Neighborparrot
#close, configuration, configure, #connected?, open, #open, #open_connection, reactor_running?, reactor_start, reactor_stop, #running?, send, #send, #send_to_broker, sign_connect_request, sign_request, sign_send_request, #start, #stop
Constructor Details
#initialize ⇒ Reactor
Start the reactor in a new thead and prepare
32 33 34 35 |
# File 'lib/neighborparrot/reactor.rb', line 32 def initialize reactor_start define_event_helpers end |
Instance Method Details
#define_event_helpers ⇒ Object
generate events helpers for instances This define tho methods: on_event(&block): Setup a block for the event trigger_event(*args): Trigger the event
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/neighborparrot/reactor.rb', line 41 def define_event_helpers @event_block = {} EVENTS.each do |event| clazz = class << self; self; end clazz.send :define_method, "on_#{event}" do |&block| @event_block[event] = block end clazz.send :define_method, "trigger_#{event}" do |*args| @event_block[event].call *args if @event_block[event] end end end |