Module: EventUtils
- Defined in:
- lib/event_utils.rb,
lib/event_utils/evented_loop.rb
Defined Under Namespace
Classes: DeferredChildFailure, DeferredLoop
Instance Method Summary collapse
-
#in_deferred_loop(&block) ⇒ Object
Wraps the clode in the provided block in an EM loop if needed.
-
#waiting_for(*deferrables, &block) ⇒ Object
waits until all the deferrables have the deferred status set and then executes the code in the provided block.
Instance Method Details
#in_deferred_loop(&block) ⇒ Object
Wraps the clode in the provided block in an EM loop if needed
in_deferred_loop do
your code using deferrables here
end
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/event_utils/evented_loop.rb', line 65 def in_deferred_loop(&block) drive_reactor = !EM.reactor_running? if drive_reactor EM.run do DeferredLoop.main_loop.callback { EM.stop } DeferredLoop.main_loop.errback { EM.stop } yield end else yield end end |
#waiting_for(*deferrables, &block) ⇒ Object
waits until all the deferrables have the deferred status set and then executes the code in the provided block
in_deferred_loop do
waiting_for deferrable_1, deferrable_2, ..., deferrable_n do
code that needs all the deferrable deferred status set here
end
end
87 88 89 90 91 |
# File 'lib/event_utils/evented_loop.rb', line 87 def waiting_for(*deferrables, &block) deferred_loop = DeferredLoop.new deferred_loop.waiting_for(*deferrables, &block) deferred_loop end |