Class: Souffle::PollingEvent
- Inherits:
-
Object
- Object
- Souffle::PollingEvent
- Defined in:
- lib/souffle/polling_event.rb
Overview
Eventmachine polling event helper.
Instance Attribute Summary collapse
-
#error_handler ⇒ Object
The proc to run when the timeout has occurred.
-
#event_loop ⇒ Object
The event loop proc, should call complete on success.
-
#interval ⇒ Object
readonly
The interval to run the periodic timer against the event_loop.
-
#node ⇒ Object
The node to run the polling event against.
-
#pre_event ⇒ Object
The proc to run prior to the periodic event loop.
-
#state ⇒ Object
The current state of the polling event.
-
#timeout ⇒ Object
readonly
The timeout (in seconds) for the periodic timer.
Instance Method Summary collapse
-
#event_complete ⇒ Object
Helper for the event block to set notify the.
-
#initialize(node, &blk) ⇒ PollingEvent
constructor
Create a new polling even instance.
-
#start_event ⇒ Object
Begin the polling event.
Constructor Details
#initialize(node, &blk) ⇒ PollingEvent
Create a new polling even instance.
45 46 47 48 49 50 51 52 |
# File 'lib/souffle/polling_event.rb', line 45 def initialize(node, &blk) @state = Hash.new @node = node instance_eval(&blk) if block_given? initialize_defaults initialize_state start_event end |
Instance Attribute Details
#error_handler ⇒ Object
The proc to run when the timeout has occurred.
24 25 26 |
# File 'lib/souffle/polling_event.rb', line 24 def error_handler @error_handler end |
#event_loop ⇒ Object
The event loop proc, should call complete on success.
21 22 23 |
# File 'lib/souffle/polling_event.rb', line 21 def event_loop @event_loop end |
#interval ⇒ Object (readonly)
The interval to run the periodic timer against the event_loop.
12 13 14 |
# File 'lib/souffle/polling_event.rb', line 12 def interval @interval end |
#node ⇒ Object
The node to run the polling event against.
6 7 8 |
# File 'lib/souffle/polling_event.rb', line 6 def node @node end |
#pre_event ⇒ Object
The proc to run prior to the periodic event loop.
18 19 20 |
# File 'lib/souffle/polling_event.rb', line 18 def pre_event @pre_event end |
#state ⇒ Object
The current state of the polling event.
9 10 11 |
# File 'lib/souffle/polling_event.rb', line 9 def state @state end |
#timeout ⇒ Object (readonly)
The timeout (in seconds) for the periodic timer.
15 16 17 |
# File 'lib/souffle/polling_event.rb', line 15 def timeout @timeout end |
Instance Method Details
#event_complete ⇒ Object
Helper for the event block to set notify the
88 89 90 91 |
# File 'lib/souffle/polling_event.rb', line 88 def event_complete @event_timer.cancel @timeout_timer.cancel end |
#start_event ⇒ Object
Begin the polling event.
78 79 80 81 82 83 84 85 |
# File 'lib/souffle/polling_event.rb', line 78 def start_event pre_event @event_timer = EM.add_periodic_timer(interval) { event_loop } @timeout_timer = EM::Timer.new(timeout) do @event_timer.cancel error_handler end end |